Open mintuz opened 8 years ago
Hello, I've come across an issue where MyStore.listen() will get called twice in my unit tests/production code if I use async code within the store. Here is my store code, the apiResolver is just a light wrapper on top of axios.
tryRegister: function(registerObj) { apiResolver.registerUser({ email: registerObj.email, password: registerObj.password, platform: 'app' }) .then(function() { this.setState({error: false, registered: true}); }.bind(this)) .catch(function(error) { this.setState({error: {title: 'Registration Failure', message: error.data}}); }.bind(this)); }
Unit test code
it.only('if successfully registered, set state object registered to true', function(done) { // Given var apiResolverMock = { registerUser: sinon.stub().returns(Promise.resolve(true)) }; resetRewires.push(rewiredAuth.__set__('apiResolver', apiResolverMock)); AuthStore.listen(function(state) { console.log(state); expect(state.registered).to.equal(true); done(); }); expect(AuthStore.state.registered).to.equal(false); // When AuthActions.tryRegister({ email: 'email@example.com', password: 'password' }); });
Hello, I've come across an issue where MyStore.listen() will get called twice in my unit tests/production code if I use async code within the store. Here is my store code, the apiResolver is just a light wrapper on top of axios.
Unit test code