Reputation: 1023
My test is passing but I am unable to achieve test coverage on a NgRX store select. this.isNIAddress$ is set in ngOnInit.
I am using Jest and setting the return value of this.isNIAddress$ within the test. If I do not do that then I get an error saying addresses inside the store is empty. How do I mock the getAllValidAddresses selector?
Error if I add the component.ngOnInit()
How do I properly test this store observable to obtain code coverage?
Upvotes: 0
Views: 237
Reputation: 74738
As per comments you can have one spy object in your spec:
spyOn(component, 'isPostcodeNI').and.returnValue(true);
component.isPostcodeNI(NiAddress[0].postcode);
expect(component.isPostcodeNI).toHaveBeenCalled();
Now you can expect the spy has been called with the postcode.
Upvotes: 0