Only gets messy when asynchronous activity is involved
Group Coding
Let's write test for receiveBenches together
Partner B teach partner A
Explain how to write a test for simple action creator
Individual Coding
Write test for receiveBench
2 minutes
receiveBench solution
test("receiveBench should create an action to receive one bench",()=>{constexpectedAction={type: actions.RECEIVE_BENCH,bench: newBench};expect(actions.receiveBench(newBench)).toEqual(expectedAction);});
10 minute break
Async Action Creator Code Demo
Let's write a test for fetchBenches
With your partner
Write tests for fetchBench
fetchBench solution
test("fetchBench creates RECEIVE_BENCH after fetching new bench",()=>{conststore=mockStore({benches: {}});constexpectedActions=[{type: actions.RECEIVE_BENCH,bench: newBench}];ApiUtil.fetchBench=jest.fn(()=>{returnPromise.resolve(newBench);});returnstore.dispatch(actions.fetchBench()).then(()=>{expect(store.getActions()).toEqual(expectedActions);});});
Component Testing
Enzyme- Enzyme is a JavaScript Testing utility for React that makes it easier to assert, manipulate, and traverse your React Components' output.
jQuery like API on components
Test what's being rendered
Test that props being passed in are used correctly