Advertisement
Guest User

test

a guest
Aug 24th, 2017
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import configureMockStore from 'redux-mock-store'
  2. import thunk from 'redux-thunk'
  3. import * as actions from '../../actions/session'
  4. import * as types from '../../constants/ActionTypes'
  5. import nock from 'nock'
  6. import expect from 'expect'
  7.  
  8. const middlewares = [thunk];
  9. const mockStore = configureMockStore(middlewares);
  10.  
  11. describe('sign-in', () => {
  12.     afterEach(() => {
  13.         nock.cleanAll()
  14.     });
  15.  
  16.     it('creates SIGN_IN when sign-in has been done', () => {
  17.         const data = {email: 'test@mail.ru', password: 'testPass'};
  18.         nock('https://localhost:7070/my')
  19.         .post('/api/v1/users/sign_in', data)
  20.         .reply(200, {
  21.             jwt: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MDM1OTQ3MDksInVzZXJfaWQiOjl9.hcPqEm4xwMj78KsrB-l1La5QlgaqqMIe4MHa1CeIyiY"
  22.         });
  23.  
  24.         const expectedActions = [
  25.             {type: types.REQUEST_SIGN_IN,},
  26.             {
  27.                 type: types.SUCCESS_SIGN_IN, token:  "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MDM1OTQ3MDksInVzZXJfaWQiOjl9.hcPqEm4xwMj78KsrB-l1La5QlgaqqMIe4MHa1CeIyiY"
  28.  
  29.             }
  30.         ];
  31.  
  32.         const store = mockStore({user: null});
  33.  
  34.         return store.dispatch(actions.signIn(data))
  35.         .then(() => { // return of async actions
  36.             expect(store.getActions()).toEqual(expectedActions)
  37.         })
  38.     })
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement