I have the following code in my react component
componentDidMount() {
ajax.call().then((data)=> {
this.setState({a:data.a});
});
}
Im making a simple call to a function that returns a promise.
My test looks like this when I am trying to test that the state gets set correctly from the resolved promise.
it('should set state of a', (done)=> {
let ajax = {
call: ()=>{}
};
spyOn(ajax, 'call').and.returnValue(Promise.resolve({a:'a'}));
let component = TestUtils.renderIntoDocument(<MyComp/>);
expect(component.state.a).toEqual('a');
});
I am pretty sure the state is actually getting set from the data returned by the promise, but the problem is I have nowhere to call the jasmine 'done()' function to tell jasmine the async operation has finished and that the assert on the state can be tested.