Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Unified Diff: packages/js_util/test/js_util_test.dart

Issue 2119523002: Added full js & js_util packages (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/js_util/src/js_util_base.dart ('k') | packages/js_util/test/js_util_test.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/js_util/test/js_util_test.dart
diff --git a/packages/js_util/test/js_util_test.dart b/packages/js_util/test/js_util_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8252c2380c9559dab4165dda02fe16b4982dccf6
--- /dev/null
+++ b/packages/js_util/test/js_util_test.dart
@@ -0,0 +1,50 @@
+@JS()
+library js_util.test;
+
+import 'package:js/js.dart';
+import 'package:js_util/js_util.dart';
+import 'package:test/test.dart';
+
+@JS('JSON.stringify')
+external String stringify(Object json);
+
+void main() {
+ group('js_util tests', () {
+ test('defineProperty test', () {
+ final obj = newObject();
+ defineProperty(
+ obj, 'foo', new PropertyDescription(enumerable: true, value: 1));
+ defineProperty(
+ obj, 'bar', new PropertyDescription(enumerable: false, value: 2));
+
+ expect(stringify(obj), '{"foo":1}');
+ });
+
+ test('newObject/setValue/getValue test', () {
+ final obj = newObject();
+ setValue(obj, 'foo', 1);
+ setValue(obj, 'bar', 2);
+
+ expect(getValue(obj, 'foo'), equals(1));
+ expect(getValue(obj, 'bar'), equals(2));
+ });
+
+ test('toJS test', () {
+ final jsObj = toJS({
+ 'people': [
+ {'firstName': 'Kwang Yul', 'lastName': 'Seo'},
+ {'firstName': 'DoHyung', 'lastName': 'Kim'},
+ {'firstName': 'Kyusun', 'lastName': 'Kim'}
+ ]
+ });
+
+ final people = getValue(jsObj, 'people');
+ expect(getValue(people[0], 'firstName'), equals('Kwang Yul'));
+ expect(getValue(people[0], 'lastName'), equals('Seo'));
+ expect(getValue(people[1], 'firstName'), equals('DoHyung'));
+ expect(getValue(people[1], 'lastName'), equals('Kim'));
+ expect(getValue(people[2], 'firstName'), equals('Kyusun'));
+ expect(getValue(people[2], 'lastName'), equals('Kim'));
+ });
+ });
+}
« no previous file with comments | « packages/js_util/src/js_util_base.dart ('k') | packages/js_util/test/js_util_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698