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 template_binding.test.template_binding_test; | 5 library template_binding.test.template_binding_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'dart:js' show JsObject; | 9 import 'dart:js' show JsObject; |
10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 // Dart note: predicate changed from 0->null because 0 isn't falsey in Dart. | 161 // Dart note: predicate changed from 0->null because 0 isn't falsey in Dart. |
162 // See https://code.google.com/p/dart/issues/detail?id=11956 | 162 // See https://code.google.com/p/dart/issues/detail?id=11956 |
163 // Changed bound from null->1 since null is equivalent to JS undefined, | 163 // Changed bound from null->1 since null is equivalent to JS undefined, |
164 // and would cause the template to not be expanded. | 164 // and would cause the template to not be expanded. |
165 var m = toObservable({ 'predicate': null, 'bound': 1 }); | 165 var m = toObservable({ 'predicate': null, 'bound': 1 }); |
166 var template = div.firstChild; | 166 var template = div.firstChild; |
167 bool errorSeen = false; | 167 bool errorSeen = false; |
168 runZoned(() { | 168 runZoned(() { |
169 templateBind(template).model = m; | 169 templateBind(template).model = m; |
170 }, onError: (e, s) { | 170 }, onError: (e, s) { |
171 expect(e, isNoSuchMethodError); | 171 _expectNoSuchMethod(e); |
172 errorSeen = true; | 172 errorSeen = true; |
173 }); | 173 }); |
174 return new Future(() { | 174 return new Future(() { |
175 expect(div.nodes.length, 1); | 175 expect(div.nodes.length, 1); |
176 | 176 |
177 m['predicate'] = 1; | 177 m['predicate'] = 1; |
178 | 178 |
179 expect(errorSeen, isFalse); | 179 expect(errorSeen, isFalse); |
180 }).then(nextMicrotask).then((_) { | 180 }).then(nextMicrotask).then((_) { |
181 expect(errorSeen, isTrue); | 181 expect(errorSeen, isTrue); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 '</template>'); | 245 '</template>'); |
246 | 246 |
247 // Dart note: changed bound from null->1 since null is equivalent to JS | 247 // Dart note: changed bound from null->1 since null is equivalent to JS |
248 // undefined, and would cause the template to not be expanded. | 248 // undefined, and would cause the template to not be expanded. |
249 var m = toObservable({ 'predicate': 1, 'bound': 1 }); | 249 var m = toObservable({ 'predicate': 1, 'bound': 1 }); |
250 var template = div.firstChild; | 250 var template = div.firstChild; |
251 bool errorSeen = false; | 251 bool errorSeen = false; |
252 runZoned(() { | 252 runZoned(() { |
253 templateBind(template).model = m; | 253 templateBind(template).model = m; |
254 }, onError: (e, s) { | 254 }, onError: (e, s) { |
255 expect(e, isNoSuchMethodError); | 255 _expectNoSuchMethod(e); |
256 errorSeen = true; | 256 errorSeen = true; |
257 }); | 257 }); |
258 | 258 |
259 return new Future(() { | 259 return new Future(() { |
260 expect(div.nodes.length, 1); | 260 expect(div.nodes.length, 1); |
261 m['bound'] = toObservable({ 'value': 2 }); | 261 m['bound'] = toObservable({ 'value': 2 }); |
262 expect(errorSeen, isTrue); | 262 expect(errorSeen, isTrue); |
263 }).then(endOfMicrotask).then((_) { | 263 }).then(endOfMicrotask).then((_) { |
264 expect(div.nodes.length, 2); | 264 expect(div.nodes.length, 2); |
265 expect(div.lastChild.text, 'value:2'); | 265 expect(div.lastChild.text, 'value:2'); |
(...skipping 2103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2369 expect(instance.firstChild.nextNode.text, 'bar:replaced'); | 2369 expect(instance.firstChild.nextNode.text, 'bar:replaced'); |
2370 | 2370 |
2371 clearAllTemplates(instance); | 2371 clearAllTemplates(instance); |
2372 }); | 2372 }); |
2373 | 2373 |
2374 test('CreateInstance - sync error', () { | 2374 test('CreateInstance - sync error', () { |
2375 var div = createTestHtml('<template>{{foo}}</template>'); | 2375 var div = createTestHtml('<template>{{foo}}</template>'); |
2376 var outer = templateBind(div.nodes.first); | 2376 var outer = templateBind(div.nodes.first); |
2377 var model = 1; // model is missing 'foo' should throw. | 2377 var model = 1; // model is missing 'foo' should throw. |
2378 expect(() => outer.createInstance(model, new TestBindingSyntax()), | 2378 expect(() => outer.createInstance(model, new TestBindingSyntax()), |
2379 throwsA(isNoSuchMethodError)); | 2379 throwsA(_isNoSuchMethodError)); |
2380 }); | 2380 }); |
2381 | 2381 |
2382 test('CreateInstance - async error', () { | 2382 test('CreateInstance - async error', () { |
2383 var div = createTestHtml( | 2383 var div = createTestHtml( |
2384 '<template>' | 2384 '<template>' |
2385 '<template bind="{{b}}">' | 2385 '<template bind="{{b}}">' |
2386 '{{ foo }}:{{ replaceme }}' | 2386 '{{ foo }}:{{ replaceme }}' |
2387 '</template>' | 2387 '</template>' |
2388 '</template>'); | 2388 '</template>'); |
2389 var outer = templateBind(div.nodes.first); | 2389 var outer = templateBind(div.nodes.first); |
2390 var model = toObservable({'b': 1}); // missing 'foo' should throw. | 2390 var model = toObservable({'b': 1}); // missing 'foo' should throw. |
2391 | 2391 |
2392 bool seen = false; | 2392 bool seen = false; |
2393 runZoned(() => outer.createInstance(model, new TestBindingSyntax()), | 2393 runZoned(() => outer.createInstance(model, new TestBindingSyntax()), |
2394 onError: (e) { | 2394 onError: (e) { |
2395 expect(e, isNoSuchMethodError); | 2395 _expectNoSuchMethod(e); |
2396 seen = true; | 2396 seen = true; |
2397 }); | 2397 }); |
2398 return new Future(() { expect(seen, isTrue); }); | 2398 return new Future(() { expect(seen, isTrue); }); |
2399 }); | 2399 }); |
2400 | 2400 |
2401 test('Repeat - svg', () { | 2401 test('Repeat - svg', () { |
2402 var div = createTestHtml( | 2402 var div = createTestHtml( |
2403 '<svg width="400" height="110">' | 2403 '<svg width="400" height="110">' |
2404 '<template repeat>' | 2404 '<template repeat>' |
2405 '<rect width="{{ width }}" height="{{ height }}" />' | 2405 '<rect width="{{ width }}" height="{{ height }}" />' |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2586 | 2586 |
2587 var a = img.nextNode; | 2587 var a = img.nextNode; |
2588 expect(a.attributes['href'], 'link.html'); | 2588 expect(a.attributes['href'], 'link.html'); |
2589 | 2589 |
2590 var input = a.nextNode; | 2590 var input = a.nextNode; |
2591 expect(input.value, '4'); | 2591 expect(input.value, '4'); |
2592 }); | 2592 }); |
2593 }); | 2593 }); |
2594 } | 2594 } |
2595 | 2595 |
2596 // TODO(jmesserly): ideally we could test the type with isNoSuchMethodError, | |
2597 // however dart:js converts the nSM into a String at some point. | |
2598 // So for now we do string comparison. | |
2599 _isNoSuchMethodError(e) => '$e'.contains('NoSuchMethodError'); | |
Jennifer Messerly
2014/06/27 01:07:25
I still need to make a repro for this bug and file
Siggi Cherem (dart-lang)
2014/06/27 18:40:52
yikes!
Jennifer Messerly
2014/06/27 19:10:03
yeah :(
I actually didn't try it on dart2js ... i
| |
2600 | |
2601 _expectNoSuchMethod(e) { | |
2602 // expect(e, isNoSuchMethodError); | |
2603 expect('$e', contains('NoSuchMethodError')); | |
2604 } | |
2605 | |
2596 class Issue285Syntax extends BindingDelegate { | 2606 class Issue285Syntax extends BindingDelegate { |
2597 prepareInstanceModel(template) { | 2607 prepareInstanceModel(template) { |
2598 if (template.id == 'del') return (val) => val * 2; | 2608 if (template.id == 'del') return (val) => val * 2; |
2599 } | 2609 } |
2600 } | 2610 } |
2601 | 2611 |
2602 class TestBindingSyntax extends BindingDelegate { | 2612 class TestBindingSyntax extends BindingDelegate { |
2603 prepareBinding(String path, name, node) { | 2613 prepareBinding(String path, name, node) { |
2604 if (path.trim() == 'replaceme') { | 2614 if (path.trim() == 'replaceme') { |
2605 return (m, n, oneTime) => new PathObserver('replaced', ''); | 2615 return (m, n, oneTime) => new PathObserver('replaced', ''); |
(...skipping 28 matching lines...) Expand all Loading... | |
2634 class TestAccessorModel extends Observable { | 2644 class TestAccessorModel extends Observable { |
2635 @observable var value = 1; | 2645 @observable var value = 1; |
2636 var count = 0; | 2646 var count = 0; |
2637 | 2647 |
2638 @reflectable | 2648 @reflectable |
2639 get prop { | 2649 get prop { |
2640 count++; | 2650 count++; |
2641 return value; | 2651 return value; |
2642 } | 2652 } |
2643 } | 2653 } |
OLD | NEW |