Mock imports to test function logic
Clash Royale CLAN TAG #URR8PPP Mock imports to test function logic Lets say I have the following file. This file imports promiseFunction from a library and I'd like to test the doSomething() function. promiseFunction doSomething() In particular, assert the states when the promise resolves or fails // file: MyComponent.js import promiseFunction from 'somewhere'; class MyClass extends Component { doSomething = () => { promiseFunction() .then((data) => { this.setState({...this.state, name: data.name}); }.catch(() => { this.setState({...this.state, error: 'error'}); }); } } How do I mock the promiseFunction thats being imported. Or really just any function that's being imported. promiseFunction // file: MyClass.spec.js it('sets error in state when doSomething() is rejected', () => { const wrapper = shallow(<MyClass />); // How do I mock promiseFunction here? wrapper.instance().doSomething()...