chore(testing): Refactor test methods to have a uniform interface.

Remove FunctionWithParamTokens.

All test wrappers async, fakeAsync and inject now return just a Function instead of FunctionWithParamTokens. This makes them directly consumable by the test framework. Also the test framework code does not have to handle a union of Function and FunctionWithParamTokens everywhere.

The Function returned by the above methods are considered asynchronous by the test framework if they return a Promise, synchronous otherwise.

Closes #8257
This commit is contained in:
Vikram Subramanian
2016-04-26 13:06:50 -07:00
committed by vikerman
parent d2efac18ed
commit 35cd0ded22
11 changed files with 186 additions and 272 deletions

View File

@ -150,6 +150,19 @@ export function main() {
expect(value).toEqual('async value');
})));
it('should allow use of "done"', (done) => {
inject([FancyService], (service) => {
let count = 0;
let id = setInterval(() => {
count++;
if (count > 2) {
clearInterval(id);
done();
}
}, 5);
})(); // inject needs to be invoked explicitly with ().
});
describe('using beforeEach', () => {
beforeEach(inject([FancyService],
(service) => { service.value = 'value modified in beforeEach'; }));
@ -174,6 +187,15 @@ export function main() {
withProviders(() => [bind(FancyService).toValue(new FancyService())])
.inject([FancyService],
(service) => { expect(service.value).toEqual('real value'); }));
it('should return value from inject', () => {
let retval = withProviders(() => [bind(FancyService).toValue(new FancyService())])
.inject([FancyService], (service) => {
expect(service.value).toEqual('real value');
return 10;
})();
expect(retval).toBe(10);
});
});
});