feat(testability): add an initial scaffold for the testability api

Make each application component register itself onto the testability
API and exports the API onto the window object.
This commit is contained in:
Julie Ralph
2015-03-23 16:46:18 -07:00
parent f68cdf3878
commit e81e5fb2b9
15 changed files with 369 additions and 4 deletions
+17
View File
@@ -19,6 +19,7 @@ import {PromiseWrapper} from 'angular2/src/facade/async';
import {bind, Inject} from 'angular2/di';
import {Template} from 'angular2/src/core/annotations/template';
import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle';
import {Testability, TestabilityRegistry} from 'angular2/src/core/testability/testability';
@Component({selector: 'hello-app'})
@Template({inline: '{{greeting}} world!'})
@@ -180,5 +181,21 @@ export function main() {
async.done();
});
}));
it('should register each application with the testability registry', inject([AsyncTestCompleter], (async) => {
var injectorPromise1 = bootstrap(HelloRootCmp, testBindings);
var injectorPromise2 = bootstrap(HelloRootCmp2, testBindings);
PromiseWrapper.all([injectorPromise1, injectorPromise2]).then((injectors) => {
var registry = injectors[0].get(TestabilityRegistry);
PromiseWrapper.all([
injectors[0].asyncGet(Testability),
injectors[1].asyncGet(Testability)]).then((testabilities) => {
expect(registry.findTestabilityInTree(el)).toEqual(testabilities[0]);
expect(registry.findTestabilityInTree(el2)).toEqual(testabilities[1]);
async.done();
});
});
}));
});
}
@@ -0,0 +1,42 @@
import {describe, ddescribe, it, iit, xit, xdescribe, expect, beforeEach} from 'angular2/test_lib';
import {Testability} from 'angular2/src/core/testability/testability';
export function main() {
describe('Testability', () => {
var testability, executed;
beforeEach(() => {
testability = new Testability();
executed = false;
});
it('should start with a pending count of 0', () => {
expect(testability.getPendingCount()).toEqual(0);
});
it('should fire whenstable callbacks if pending count is 0', () => {
testability.whenStable(() => executed = true);
expect(executed).toBe(true);
});
it('should not call whenstable callbacks when there are pending counts', () => {
testability.increaseCount(2);
testability.whenStable(() => executed = true);
expect(executed).toBe(false);
testability.increaseCount(-1);
expect(executed).toBe(false);
});
it('should fire whenstable callbacks when pending drops to 0', () => {
testability.increaseCount(2);
testability.whenStable(() => executed = true);
expect(executed).toBe(false);
testability.increaseCount(-2);
expect(executed).toBe(true);
});
});
}