I am trying to assert the values of windows object using jest. For example: Asserting google tag manager's window.dataLayer values.
How can I implement that using unit testing jest framework?
I am trying to assert the values of windows object using jest. For example: Asserting google tag manager's window.dataLayer values.
How can I implement that using unit testing jest framework?
If you want to call a object which you will find in window.dataLayer
object, just mock the function you will call:
window.dataLayer = jest.fn(() => {
push: jest.fn(),
});
before you test your functionality.
In case you want to use in multiple test, you can set in beforeAll