From 5080d0491fbcace25d64982f59c0154351c72936 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 18 Sep 2023 11:19:07 -0700 Subject: [PATCH] Review feedback from globalContext change (#69) 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); + }); +}