我有这段代码:
import amplitude from 'amplitude-js/amplitude';
export const initAmplitude = () => {
amplitude.getInstance().init(process.env.REACT_APP_AMPLITUDE);
};
这是测试:
import amplitude from 'amplitude-js/amplitude';
import { initAmplitude } from './amplitude';
jest.mock('amplitude-js/amplitude', () => ({
getInstance: () => ({
init: () => jest.fn()
})
}));
describe('amplitude', () => {
describe('initAmplitude', () => {
it('should init amplitude', () => {
initAmplitude();
expect(amplitude.getInstance().init()).toHaveBeenCalledTimes(1);
});
});
});
我不知道为什么但是没有接到电话:
Expected mock function to have been called one time, but it was called zero times.
如果我将console.logs
打印出来,那么我知道它已经到了那里。