我在我的
test/__mocks__
我模拟NPM模块的文件夹。这个文件的链接被添加到我的jest设置中。一切都很好,这让我很好地测试它。但是现在对于一个特定的测试,我需要改变这个返回值。我怎样才能做到这一点?
我试着解除锁定加上setmock等,但没有任何效果。
// test/__mocks__/touchId.ts
jest.mock('react-native-touch-id', () => {
return {
isSupported: jest.fn(() => Promise.resolve(true)),
authenticate: jest.fn(() => Promise.resolve(true)),
};
});
还有我的测试
it('should not navigate to main if touch id return false', async () => {
jest.setMock('react-native-touch-id', {
authenticate: jest.fn(() => Promise.resolve(false)),
});
const pinCreation = new PinCreationStore();
const spy = jest.spyOn(NavigationServices, 'navigate');
spy.mockReset();
await pinCreation.verifyUser();
expect(spy).toHaveBeenCalledTimes(0);
spy.mockRestore();
});
在这里我仍然是真的,所以我的测试崩溃了。