Advertisement
fabiobiondi

Mock Axios in Unit Test with Jest and Moxios

Aug 22nd, 2017
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   it('expected actions should be dispatched on successful request', () => {
  2.     moxios.stubRequest('http://localhost:3001/activities', {
  3.       status: 200,
  4.       response: []
  5.     });
  6.  
  7.     const store = mockStore({})
  8.     const expectedActions = [
  9.       'ACTIVITY_PENDING',
  10.       'ACTIVITY_GET_ALL'
  11.     ];
  12.  
  13.     return store.dispatch(actions.getActivities({}))
  14.       .then(() => {
  15.         const actualActions = store.getActions().map(action => action.type)
  16.         expect(actualActions).toEqual(expectedActions)
  17.       })
  18.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement