Skip to content

Instantly share code, notes, and snippets.

@nikfrank
Last active June 1, 2017 20:35
Show Gist options
  • Save nikfrank/4d78becef230c0b1d1096a83af878aee to your computer and use it in GitHub Desktop.
Save nikfrank/4d78becef230c0b1d1096a83af878aee to your computer and use it in GitHub Desktop.
React (crazy straw ugly flow) async user scenario test
it('adds a todo, then resets the device', (done) => {
// ... set up component and stores ...
// we're going to add a todo, then reset to the initState
expect( reduxStore.getState().get('todos').size )
.toEqual( TodoList.initState.get('todos').size );
// flow is backwards for async ops below
const clickResetAndCheck = ()=>{
const unsubscribe = reduxStore.subscribe(()=>{
expect( reduxStore.getState().get('todos').size )
.toEqual( TodoList.initState.get('todos').size );
unsubscribe();
done();
});
const resetButton = mountedComponent.find('button.reset').first();
resetButton.simulate('click');
};
const unsubscribe = reduxStore.subscribe(()=>{
expect( reduxStore.getState().get('todos').size )
.toEqual( TodoList.initState.get('todos').size + 1 );
unsubscribe();
clickResetAndCheck();
});
const addTodoButton = mountedComponent.find('button.addTodo').first();
addTodoButton.simulate('click');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment