A crucial point to note is the inclusion of brackets after the inject
function call. For example:
inject(function(someServices) {
//some asynchronous test
done();
})(); <-- these brackets are important here.
If you examine the type of inject
:
export declare function inject(tokens: any[], fn: Function): () => any;
You can see that it returns a function, which explains why there was no output - because you forgot to invoke the function!!
When you think about it, it makes sense that it returns a function since it
expects a function!
Therefore, adding extra parentheses should resolve all issues!
Example in Action:
it('should allow you to observe for changes', function(done) {
inject([GlobalStateService], (globalStateService: GlobalStateService) => {
globalStateService.observe("user", storageType.InMemoryStorage, (user: string) => {
expect(user).toBe("bla");
done();
});
globalStateService.write({ user: "bla"}, storageType.InMemoryStorage);
})();
});