OLD | NEW |
(Empty) | |
| 1 @JS() |
| 2 library js_util.test; |
| 3 |
| 4 import 'package:js/js.dart'; |
| 5 import 'package:js_util/js_util.dart'; |
| 6 import 'package:test/test.dart'; |
| 7 |
| 8 @JS('JSON.stringify') |
| 9 external String stringify(Object json); |
| 10 |
| 11 void main() { |
| 12 group('js_util tests', () { |
| 13 test('defineProperty test', () { |
| 14 final obj = newObject(); |
| 15 defineProperty( |
| 16 obj, 'foo', new PropertyDescription(enumerable: true, value: 1)); |
| 17 defineProperty( |
| 18 obj, 'bar', new PropertyDescription(enumerable: false, value: 2)); |
| 19 |
| 20 expect(stringify(obj), '{"foo":1}'); |
| 21 }); |
| 22 |
| 23 test('newObject/setValue/getValue test', () { |
| 24 final obj = newObject(); |
| 25 setValue(obj, 'foo', 1); |
| 26 setValue(obj, 'bar', 2); |
| 27 |
| 28 expect(getValue(obj, 'foo'), equals(1)); |
| 29 expect(getValue(obj, 'bar'), equals(2)); |
| 30 }); |
| 31 |
| 32 test('toJS test', () { |
| 33 final jsObj = toJS({ |
| 34 'people': [ |
| 35 {'firstName': 'Kwang Yul', 'lastName': 'Seo'}, |
| 36 {'firstName': 'DoHyung', 'lastName': 'Kim'}, |
| 37 {'firstName': 'Kyusun', 'lastName': 'Kim'} |
| 38 ] |
| 39 }); |
| 40 |
| 41 final people = getValue(jsObj, 'people'); |
| 42 expect(getValue(people[0], 'firstName'), equals('Kwang Yul')); |
| 43 expect(getValue(people[0], 'lastName'), equals('Seo')); |
| 44 expect(getValue(people[1], 'firstName'), equals('DoHyung')); |
| 45 expect(getValue(people[1], 'lastName'), equals('Kim')); |
| 46 expect(getValue(people[2], 'firstName'), equals('Kyusun')); |
| 47 expect(getValue(people[2], 'lastName'), equals('Kim')); |
| 48 }); |
| 49 }); |
| 50 } |
OLD | NEW |