Home > Software design >  Jest - ReferenceError: spyOn is not defined
Jest - ReferenceError: spyOn is not defined

Time:12-01

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!

CodePudding user response:

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

jest.spyOn(validationFacade, 'validateOrder').mockReturnValue(of(validationResponseMock));

Hope this help. Thanks!

  • Related