I have the following function in my component:
method(args) { fetch(args) .then((response) => { this.setState({ element: response error: false }); }) .catch((error) => { this.setState({ error: true }); }); }
I am trying to write a unit test for it, so I made fun of calling fetch with fetch-mock with a custom answer. I want to check if the state was updated when this method was called and it does not seem to work. I use an enzyme, expect and sine, and failed to get a spy call when I set the component .setState = sinon.spy or terminate it. How can I check if setState was called with certain elements, or my approach to the module, checking this incorrectly?
unit-testing reactjs sinon enzyme
intuition17
source share