OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 testObservableValue() { | 5 testObservableValue() { |
6 test('ObservableValue', () { | 6 test('ObservableValue', () { |
7 final value = new ObservableValue<String>('initial'); | 7 final value = new ObservableValue<String>('initial'); |
8 expect(value.value).equals('initial'); | 8 expect(value.value, equals('initial')); |
9 | 9 |
10 // Set value. | 10 // Set value. |
11 value.value = 'new'; | 11 value.value = 'new'; |
12 expect(value.value).equals('new'); | 12 expect(value.value, equals('new')); |
13 | 13 |
14 // Change event is sent when value is changed. | 14 // Change event is sent when value is changed. |
15 EventSummary result = null; | 15 EventSummary result = null; |
16 value.addChangeListener((summary) { | 16 value.addChangeListener((summary) { |
17 expect(result).isNull(); | 17 expect(result, isNull); |
18 result = summary; | 18 result = summary; |
19 expect(result).isNotNull(); | 19 expect(result, isNotNull); |
20 }); | 20 }); |
21 | 21 |
22 value.value = 'newer'; | 22 value.value = 'newer'; |
23 | 23 |
24 expect(result).isNotNull(); | 24 expect(result, isNotNull); |
25 expect(result.events.length).equals(1); | 25 expect(result.events.length, equals(1)); |
26 validateUpdate(result.events[0], value, 'value', null, 'newer', 'new'); | 26 validateUpdate(result.events[0], value, 'value', null, 'newer', 'new'); |
27 }); | 27 }); |
28 | 28 |
29 test('does not raise event if unchanged', () { | 29 test('does not raise event if unchanged', () { |
30 final value = new ObservableValue<String>('foo'); | 30 final value = new ObservableValue<String>('foo'); |
31 expect(value.value).equals('foo'); | 31 expect(value.value, equals('foo')); |
32 | 32 |
33 bool called = false; | 33 bool called = false; |
34 value.addChangeListener((summary) { called = true; }); | 34 value.addChangeListener((summary) { called = true; }); |
35 | 35 |
36 // Set it to the same value. | 36 // Set it to the same value. |
37 value.value = 'foo'; | 37 value.value = 'foo'; |
38 | 38 |
39 // Should not have gotten an event. | 39 // Should not have gotten an event. |
40 expect(called).equals(false); | 40 expect(called, isFalse); |
41 }); | 41 }); |
42 } | 42 } |
OLD | NEW |