Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest - ReferenceError: spyOn is not defined

I am trying to mock a return value from a subscription's in my angular unit test. Found tons of example, but all are using spyOn in combination with .and.returnValue(of()). For spyOn i am getting

ReferenceError: spyOn is not defined

So changed it to jest.spyOn but now I am getting the error:

Property 'and' does not exist on type 'SpyInstance<void, [request: ValidationRequest]>'

my code is:

jest.spyOn(validationFacade, 'validateOrder').and.returnValue(of(validationResponseMock).pipe(delay(1)));

Please help how to replace .and.returnValue(of())!

Thanks in advance for you help!

like image 254
szelelaci Avatar asked Dec 30 '25 00:12

szelelaci


1 Answers

As per my understanding you are writing in Angular with Jest. If I am right, Please try this way. It worked for me:

jest.spyOn(validationFacade, 'validateOrder').mockReturnValue(of(validationResponseMock));
like image 84
Vivek Avatar answered Dec 31 '25 14:12

Vivek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!