I'm following the angular official doc and I can see this code:
it("#getObservableValue should return value from observable", (done: DoneFn) => {
service.getObservableValue().subscribe(value => {
expect(value).toBe("observable value");
done();
});
});
I'm wondering where DoneFn comes from because I've no error either import for the typing.
In almost all cases, they can be used interchangeably, but using fakeAsync()/tick() combo is preferred unless you need to make an XHR call, in which case you MUST use async()/whenStable() combo, as fakeAsync() does not support XHR calls. For the most part they can be used interchangeably.
The tick() function simulates the asynchronous passage of time for the timers in the fakeAsync zone in Angular test.
If Angular CLI is used to manage the Angular projects, it will automatically support Jasmine and Karma Configurations. All you need in order to test your application is to type the command ng test. As far as possible, run tests on real browsers and devices to ensure that software is verified under real user conditions.
Test the Component logic using SpyOn. SpyOn is a Jasmine feature that allows dynamically intercepting the calls to a function and change its result. This example shows how spyOn works, even if we are still mocking up our service.
If you follow the Interface definition you will see that it is under:
node_modules/@types/jasmine/index.d.ts
/** Action method that should be called when the async work is complete */
interface DoneFn extends Function {
(): void;
/** fails the spec and indicates that it has completed. If the message is an Error, Error.message is used */
fail: (message?: Error | string) => void;
}
You don't need to import or use it, it's mostly for reference. I am not sure how @types
exactly work but I suppose if there is a @types
typing within the project, node knows how to find the definition as they are all indexed in this one folder.
UPDATE:
I found out this is being configured by tsconfig.json
"typeRoots": [
"node_modules/@types"
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With