Skip to content

Commit d901069

Browse files
vicbdsalsbury
authored andcommitted
test(dccd): Add a test for swapping references
closes dart-archive#1158 Closes dart-archive#1253
1 parent 5eedd38 commit d901069

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/change_detection/dirty_checking_change_detector_spec.dart

+27
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,33 @@ void testWithGetterFactory(FieldGetterFactory getterFactory) {
271271
removals: []));
272272
});
273273

274+
it('should support switching refs - gh 1158', async(() {
275+
var list = [0];
276+
277+
var record = detector.watch(list, null, null);
278+
if (detector.collectChanges().moveNext()) {
279+
detector.collectChanges();
280+
}
281+
282+
record.object = [1, 0];
283+
var iterator = detector.collectChanges()..moveNext();
284+
expect(iterator.current.currentValue, toEqualCollectionRecord(
285+
collection: ['1[null -> 0]', '0[0 -> 1]'],
286+
previous: ['0[0 -> 1]'],
287+
additions: ['1[null -> 0]'],
288+
moves: ['0[0 -> 1]'],
289+
removals: []));
290+
291+
record.object = [2, 1, 0];
292+
iterator = detector.collectChanges()..moveNext();
293+
expect(iterator.current.currentValue, toEqualCollectionRecord(
294+
collection: ['2[null -> 0]', '1[null -> 1]', '0[0 -> 2]'],
295+
previous: ['0[0 -> 2]'],
296+
additions: ['2[null -> 0]', '1[null -> 1]'],
297+
moves: ['0[0 -> 2]'],
298+
removals: []));
299+
}));
300+
274301
it('should handle swapping elements correctly', () {
275302
var list = [1, 2];
276303
var record = detector.watch(list, null, null);

0 commit comments

Comments
 (0)