I'm trying to get jest mocking to work on a relative path. The same code but with mocking fs
worked great, so I'm not sure why trying to mock my own modules doesn't work
// myFile.js
const cacheHandler = require('./cacheHandler.js')
const myFunc = () => {
cacheHandler.cacheFile(file_name)
}
// myFile.spec.js
const myFile = require('./myFile.js')
const cacheHandler = require('./cacheHandler.js')
jest.mock('./cacheHandler')
describe("my failing test :( ", () =>{
it("should be able to spy on the function", () => {
cacheHandler.cacheFile = jest.fn()
myFile.myFunc()
expect(cacheHandler.cacheFile).toBeCalledTimes(1)
}
}
jest claims that the cacheFile() was never called, eventhough when I debug this I can see that it reached this function...
What am I missing?
Aucun commentaire:
Enregistrer un commentaire