Consider code -
// utils.js
export const foo = async (a, b) => {
// do something
bar(a)
}
export const bar = async (a) => {
// do something
}
// utils.spec.js
const utils = require('./utils');
const barSpy = jest.spyOn(utils, 'bar');
const result = await utils.foo('a', 'b');
expect(barSpy).toHaveBeenCalledTimes(1);
The test is failing -
Error: expect(jest.fn()).toHaveBeenCalledTimes(expected)
Expected number of calls: 1
Received number of calls: 0
I read https://medium.com/@DavideRama/mock-spy-exported-functions-within-a-single-module-in-jest-cdf2b61af642 and https://github.com/facebook/jest/issues/936 but could not solve this with multiple permutations.
Do you see any issue with this?
from Jest method-invocation count is wrong?
No comments:
Post a Comment