| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library bindings_test; | 5 library bindings_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 | 9 |
| 10 import 'package:observe/observe.dart'; | 10 import 'package:observe/observe.dart'; |
| 11 import 'package:observe/mirrors_used.dart'; // make test smaller. | 11 import 'package:observe/mirrors_used.dart'; // make test smaller. |
| 12 import 'package:observe/src/dirty_check.dart' show dirtyCheckZone; | 12 import 'package:observe/src/dirty_check.dart' show dirtyCheckZone; |
| 13 import 'package:polymer_expressions/polymer_expressions.dart'; | 13 import 'package:polymer_expressions/polymer_expressions.dart'; |
| 14 import 'package:smoke/mirrors.dart' as smoke; | 14 import 'package:smoke/mirrors.dart' as smoke; |
| 15 import 'package:template_binding/template_binding.dart' show | 15 import 'package:template_binding/template_binding.dart' show |
| 16 TemplateBindExtension, templateBind; | 16 TemplateBindExtension, templateBind; |
| 17 import 'package:unittest/html_config.dart'; | 17 import 'package:unittest/html_config.dart'; |
| 18 | 18 |
| 19 import 'package:unittest/unittest.dart'; | 19 import 'package:unittest/unittest.dart'; |
| 20 | 20 |
| 21 var testDiv; | 21 var testDiv; |
| 22 | 22 |
| 23 main() => dirtyCheckZone().run(() { | 23 main() => dirtyCheckZone().run(() { |
| 24 useHtmlConfiguration(); | 24 useHtmlConfiguration(); |
| 25 smoke.useMirrors(); |
| 25 | 26 |
| 26 group('bindings', () { | 27 group('bindings', () { |
| 27 var stop = null; | 28 var stop = null; |
| 28 setUp(() { | 29 setUp(() { |
| 29 document.body.append(testDiv = new DivElement()); | 30 document.body.append(testDiv = new DivElement()); |
| 30 }); | 31 }); |
| 31 | 32 |
| 32 tearDown(() { | 33 tearDown(() { |
| 33 testDiv.remove(); | 34 testDiv.remove(); |
| 34 testDiv = null; | 35 testDiv = null; |
| 35 }); | 36 }); |
| 36 | 37 |
| 37 test('should update binding when data changes', () { | 38 test('should update binding when data changes', () { |
| 38 var model = new NotifyModel(); | 39 var model = new NotifyModel(); |
| 39 var binding = new PolymerExpressions() | 40 var binding = new PolymerExpressions() |
| 40 .prepareBinding('x', null, null)(model, null, false); | 41 .prepareBinding('x', null, null)(model, null, false); |
| 41 expect(binding.value, isNull); | 42 expect(binding.value, isNull); |
| 42 model.x = "hi"; | 43 model.x = "hi"; |
| 43 return new Future(() { | 44 return new Future(() { |
| 44 expect(binding.value, 'hi'); | 45 expect(binding.value, 'hi'); |
| 45 }); | 46 }); |
| 46 }); | 47 }); |
| 47 | 48 |
| 49 // regression test for issue 19296 |
| 50 test('should not throw when data changes', () { |
| 51 var model = new NotifyModel(); |
| 52 var tag = new Element.html('<template>' |
| 53 '<template repeat="{{ i in x }}">{{ i }}</template></template>'); |
| 54 TemplateBindExtension.bootstrap(tag); |
| 55 var template = templateBind(tag); |
| 56 testDiv.append(template.createInstance(model, new PolymerExpressions())); |
| 57 |
| 58 return new Future(() { |
| 59 model.x = [1, 2, 3]; |
| 60 }).then(_nextMicrotask).then((_) { |
| 61 expect(testDiv.text,'123'); |
| 62 }); |
| 63 }); |
| 64 |
| 65 |
| 48 test('should update text content when data changes', () { | 66 test('should update text content when data changes', () { |
| 49 var model = new NotifyModel('abcde'); | 67 var model = new NotifyModel('abcde'); |
| 50 var tag = new Element.html( | 68 var tag = new Element.html( |
| 51 '<template><span>{{x}}</span></template>'); | 69 '<template><span>{{x}}</span></template>'); |
| 52 TemplateBindExtension.bootstrap(tag); | 70 TemplateBindExtension.bootstrap(tag); |
| 53 var template = templateBind(tag); | 71 var template = templateBind(tag); |
| 54 testDiv.append(template.createInstance(model, new PolymerExpressions())); | 72 testDiv.append(template.createInstance(model, new PolymerExpressions())); |
| 55 | 73 |
| 56 var el; | 74 var el; |
| 57 return new Future(() { | 75 return new Future(() { |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 get y => _y; | 311 get y => _y; |
| 294 set y(value) { | 312 set y(value) { |
| 295 _y = notifyPropertyChange(#y, _y, value); | 313 _y = notifyPropertyChange(#y, _y, value); |
| 296 } | 314 } |
| 297 } | 315 } |
| 298 | 316 |
| 299 class _NullTreeSanitizer implements NodeTreeSanitizer { | 317 class _NullTreeSanitizer implements NodeTreeSanitizer { |
| 300 void sanitizeTree(Node node) {} | 318 void sanitizeTree(Node node) {} |
| 301 } | 319 } |
| 302 final _nullTreeSanitizer = new _NullTreeSanitizer(); | 320 final _nullTreeSanitizer = new _NullTreeSanitizer(); |
| OLD | NEW |