I am migrating from jasmine to jest in my application. I have the following line to test
JSON.parse(window.document.querySelector(SELECTOR).innerHTML)
In my test I used jasmine.
document.querySelector = jasmine.createSpy('HTML Element').and.returnValue(dummyEl)
But now with jest I get the following error
TypeError: Cannot read property 'innerHTML' of null
Can you help me?
>Solution :
I think you need a combination of jest.fn and .mockReturnValue.
I am not good with jest but I think it can be:
document.querySelector = jest.fn().mockReturnValue(dummyEl);
Check out the documentation here:
https://jestjs.io/docs/jest-object#jestfnimplementation
https://jestjs.io/docs/mock-function-api#mockfnmockimplementationfn