我似乎无法弄清楚为什么这个测试失败了;我已将问题减少到这两个文件..
[文件:esm-user.js]
const getJack = () => {return 'Jack';};
const getJill = () => {return 'Jill';};
const getUsers = () => {return [getJack(), getJill()];};
export default { getUsers, getJack };
[文件:esm-user-spy.spec.js]
import users from './esm-user';
describe("Mocks and Spies", () => {
test.only("partial mock (jack)", () => {
var getJackSpy = jest.spyOn(users, 'getJack').mockReturnValue('Mock Jack');
expect(users.getUsers()).toEqual(['Mock Jack', 'Jill']);
});
});
[输出]
expect(received).toEqual(expected) // deep equality
Array [
- "Mock Jack",
+ "Jack",
"Jill",
]