У меня есть компонент, в котором ComponentDidMount пытается вызвать функцию API.
componentDidMount(){
this.getTypes(this.props.user).then(Response => {this.setState({List: Response.Types })});
}
async getTypes(userLogin){
try{
res = await API.get(......... );
}
catch(error) {
....
}
}
Теперь я хочу вызвать componentDidMount и getTypes и имитирую API.get.
Итак для этого может кто-нибудь сказать мне, как вызвать как componentDidMount, так и getTypes с помощью Jest?
EDIT: Пытался сделать таким образом. Но я вижу, что он не вызывает ComponentDidMount.
it('renders ComponentDidMount', () => {
const wrapper = shallow(<HoldVendor region={"aaa"} applier={"xxx"} />);
API.get = jest.fn().mockImplementation(
() => {
return {"Types": [{}]};
});
expect(API.get).toHaveBeenCalled();
});