0
在我的組件我有...spyOn失敗,即使間諜被稱爲
onSubmit = (e) => {
e.preventDefault();
const { history, versionStore } = this.props;
versionStore.add(this.state.formData)
.then(() => history.push('/'));
}
在我的測試...
it('after successfully submit should redirect to/page',() => {
const spy = jest.spyOn(minProps.history, 'push')
.mockImplementation((path) => {
console.log('called with ', path); // IS CALLED!
});
const wrapper = shallow(<Add.wrappedComponent {...minProps} />);
fetchMock.postOnce('/api/version', { name: 'v1' });
wrapper.setState({ formData: { name: 'v1' } });
wrapper.find('form').simulate('submit', { preventDefault: jest.fn() });
expect(spy).toHaveBeenCalledWith('/');
spy.mockReset();
spy.mockRestore();
});
測試失敗,
稱爲與/
expect(jest.fn()).HandBeenCalledWith(expected)預期的模擬函數被稱爲:[「/」]
但它沒有被調用。