I want to spy on a function which is defined in a separate file and called by multiple react components.
for example I have this test.js file:
export const func = {
call: (e) => console.log(e),
};
This is imported by multiple React components and i want to spy on this function with cypress but its never called:
import { func } from "../../src/test";
describe("template spec", () => {
it("calls func.call", () => {
cy.visit("/");
cy.spy(func, "call");
//some more code ...
expect(func.call).to.be.called
});
});
I’m new to testing with cypress, so i might have misunderstood the concept of spying. What am i doing wrong?