angular-cn/modules/change_detection/test/change_detection_spec.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

import {describe, it, xit, expect} from 'test_lib/test_lib';
import {ProtoWatchGroup, WatchGroup, WatchGroupDispatcher, ChangeDetection} from 'change_detection/change_detection';
2014-09-30 16:39:37 -07:00
export function main() {
describe('change_detection', function() {
describe('ChangeDetection', function() {
xit('should do simple watching', function() {
2014-09-30 16:39:37 -07:00
var person = new Person('misko', 38);
var pwg = new ProtoWatchGroup();
pwg.watch('name', 'nameToken');
pwg.watch('age', 'ageToken');
var dispatcher = new LoggingDispatcher();
var wg = pwg.instantiate(dispatcher);
wg.setContext(person);
var cd = new ChangeDetection(wg);
cd.detectChanges();
expect(dispatcher.log).toEqual(['ageToken=38']);
dispatcher.clear();
cd.detectChanges();
expect(dispatcher.log).toEqual([]);
person.age=1;
person.name="Misko";
cd.detectChanges();
expect(dispatcher.log).toEqual(['nameToken=Misko', 'ageToken=1']);
});
});
});
}
class Person {
constructor(name:string, age:number) {
this.name = name;
this.age = age;
2014-09-30 16:39:37 -07:00
}
}
class LoggingDispatcher extends WatchGroupDispatcher {
constructor() {
this.log = null;
}
clear() {
2014-09-30 16:39:37 -07:00
}
2014-09-30 16:39:37 -07:00
}