From 11fd4855d6a855dc43fb743a9e5662e6c0ded2f3 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 18 Sep 2023 10:54:50 -0700 Subject: [PATCH] Review feedback from globalContext change And add test --- lib/helpers.dart | 2 +- pubspec.yaml | 2 +- test/helpers_test.dart | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/helpers_test.dart diff --git a/lib/helpers.dart b/lib/helpers.dart index 8866a78e..3bd68168 100644 --- a/lib/helpers.dart +++ b/lib/helpers.dart @@ -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; } diff --git a/pubspec.yaml b/pubspec.yaml index fa7226bd..2f195059 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/helpers_test.dart b/test/helpers_test.dart new file mode 100644 index 00000000..f750b16a --- /dev/null +++ b/test/helpers_test.dart @@ -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); + }); +}