I'm new to Jasmine, and am getting this error:
Expected spy unknown to have been called.
What does this mean? I'm spying on a method, but am not sure what unknown
means.
I'm new to Jasmine, and am getting this error:
Expected spy unknown to have been called.
What does this mean? I'm spying on a method, but am not sure what unknown
means.
The answer is really simple! The spy didnt have a name, so it's called "unknown" by default.
To name it, I simply did this
var mySpy = jasmine.createSpy("JamesBond");
Then it failed with something more readable!
Expected spy JamesBond to have been called.
The "unknown" value is due to the inexistence of the name attribution for the spy.
before: Error: Expected spy unknown.getPlans to have been called.
const mockPlansServiceEmpty: Spide<PlansService> = jasmine.createSpyObj(
['getPlans', 'separateValidFromInvalidPlans']
);
after: Error: Expected spy mockPlansEmpty.getPlans to have been called.
const mockPlansServiceEmpty: Spide<PlansService> = jasmine.createSpyObj(
'mockPlansEmpty',
['getPlans', 'separateValidFromInvalidPlans']
);
If you are using the service with promise then you can use async await in the test case.
it ('should check the testAngular with error return', **fakeAsync**( () => {
// Arrange
let promise = Promise.reject(Error);
testAngular.error = jasmine.createSpy();
testAngular.yourfunctioname= jasmine.createSpy().and.returnValue(promise);
//Act
**await** fixture.detectChanges();
// Assert
**flush()**
expect(alertServiceSpy.error).toHaveBeenCalledWith(Error);
}));
© 2022 - 2024 — McMap. All rights reserved.