Skip to content

Commit

Permalink
Review feedback from globalContext change (#69)
Browse files Browse the repository at this point in the history
And add test
  • Loading branch information
kevmoo authored Sep 18, 2023
1 parent 57353c1 commit 5080d04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Element? querySelector(String selectors) => document.querySelector(selectors);

bool isInstanceOfDomType(JSObject? o, String domType) {
if (o == null) return false;
final constructor = globalContext.getProperty(domType.toJS);
final constructor = globalContext[domType];
if (constructor == null) return false;
return o.instanceof(constructor as JSFunction).toDart;
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version: 0.1.5-wip
repository: https://github.com/dart-lang/web

environment:
sdk: ">=3.2.0-75.0.dev <4.0.0"
sdk: ">=3.2.0-157.0.dev <4.0.0"

dev_dependencies:
args: ^2.4.0
Expand Down
18 changes: 18 additions & 0 deletions test/helpers_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@TestOn('browser')
library;

import 'package:test/test.dart';
import 'package:web/helpers.dart';

void main() {
test('isInstanceOfDomType', () {
final div = document.createElement('div');

expect(isInstanceOfDomType(div, 'bob'), false);
expect(isInstanceOfDomType(div, 'HTMLDivElement'), true);
});
}

0 comments on commit 5080d04

Please sign in to comment.