0👍
✅
Because your original method returns a promise, and your spy is also returning a promise (even an already resolved) you should use the then
or the async
await
as you commented in the question.
So, the other way of doing is:
it('should set X', (done) => {
vm.getSomething().then(() => {
expect(vm.X).toBe(X);
done();
});
})
Using the done
parameter from jasmine to notify this unit test is asynchronous and will complete when this callback is called.
0👍
i know it’s a little bit too late and you probably already found a solution, but in case you didn’t i think that the solution i will propose will work for you. You can use the combination of fakeAsync and tick to test your asynchronous function, bellow is my solution.
describe('test', () => {
...
it('should set X', fakeAsync(() =>{
vm.getSomething();
tick();
expect(vm.X).toBe(X);
}));
...
}
Source:stackexchange.com