feat(testability): Expose function frameworkStabilizers

Closes #5485
This commit is contained in:
Hank Duan
2016-01-05 12:56:24 -08:00
parent 95248f46a1
commit 69ae3634c7
6 changed files with 159 additions and 8 deletions
@@ -43,12 +43,13 @@ class MockNgZone extends NgZone {
export function main() {
describe('Testability', () => {
var testability, execute, ngZone;
var testability, execute, execute2, ngZone;
beforeEach(() => {
ngZone = new MockNgZone();
testability = new Testability(ngZone);
execute = new SpyObject().spy('execute');
execute2 = new SpyObject().spy('execute');
});
describe('Pending count logic', () => {
@@ -109,6 +110,35 @@ export function main() {
expect(execute).not.toHaveBeenCalled();
});
it('should fire whenstable callbacks with didWork if pending count is 0',
inject([AsyncTestCompleter], (async) => {
testability.whenStable(execute);
microTask(() => {
expect(execute).toHaveBeenCalledWith(false);
async.done();
});
}));
it('should fire whenstable callbacks with didWork when pending drops to 0',
inject([AsyncTestCompleter], (async) => {
testability.increasePendingRequestCount();
testability.whenStable(execute);
microTask(() => {
testability.decreasePendingRequestCount();
microTask(() => {
expect(execute).toHaveBeenCalledWith(true);
testability.whenStable(execute2);
microTask(() => {
expect(execute2).toHaveBeenCalledWith(false);
async.done();
});
});
});
}));
});
describe('NgZone callback logic', () => {
@@ -208,6 +238,43 @@ export function main() {
});
});
}));
it('should fire whenstable callback with didWork if event is already finished',
inject([AsyncTestCompleter], (async) => {
ngZone.start();
ngZone.finish();
testability.whenStable(execute);
microTask(() => {
expect(execute).toHaveBeenCalledWith(true);
testability.whenStable(execute2);
microTask(() => {
expect(execute2).toHaveBeenCalledWith(false);
async.done();
});
});
}));
it('should fire whenstable callback with didwork when event finishes',
inject([AsyncTestCompleter], (async) => {
ngZone.start();
testability.whenStable(execute);
microTask(() => {
ngZone.finish();
microTask(() => {
expect(execute).toHaveBeenCalledWith(true);
testability.whenStable(execute2);
microTask(() => {
expect(execute2).toHaveBeenCalledWith(false);
async.done();
});
});
});
}));
});
});
}