Last active
June 1, 2017 20:35
-
-
Save nikfrank/4d78becef230c0b1d1096a83af878aee to your computer and use it in GitHub Desktop.
React (crazy straw ugly flow) async user scenario test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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