@@ -13,6 +13,8 @@ const middlewares = [thunk]
1313const mockStore = configureStore ( middlewares ) ;
1414let store = mockStore ( { } ) ;
1515let mock = new MockAdapter ( axios )
16+ const nextStep = jest . fn ( ) ;
17+
1618describe ( 'Fetch Signup actions' , ( ) => {
1719
1820 beforeEach ( ( ) => {
@@ -22,11 +24,22 @@ describe('Fetch Signup actions', () => {
2224 afterEach ( ( ) => moxios . uninstall ( ) )
2325
2426 it ( 'Creates REQUEST_ERROR after task is unsuccessful' , ( ) => {
25- mock . onGet ( `${ URL } /user/signup` )
26- . reply ( 400 , { response :{ error : "\"username\" length must be at least 5 characters long" } } )
27- store . dispatch ( actions . requestSignup ( ) ) . then ( ( res ) => {
28- //const action=[{type:'FETCH_LOCATIONS_SUCCESS',payload:locationsPayload }]
29- const expectedActions = store . getActions ( )
27+
28+ moxios . wait ( ( ) => {
29+ const request = moxios . requests . mostRecent ( )
30+ request . reject ( {
31+ status : 400 ,
32+ response : {
33+ data :{
34+ error : "\"username\" length must be at least 5 characters long" ,
35+ }
36+ }
37+
38+ } )
39+ } )
40+
41+ return store . dispatch ( actions . requestSignup ( ) ) . then ( ( ) => {
42+ const expectedActions = store . getActions ( ) ;
3043 expect ( expectedActions [ 0 ] . type ) . toEqual ( 'REQUEST_SIGNUP' )
3144 expect ( expectedActions [ 1 ] . type ) . toEqual ( 'REQUEST_ERROR' )
3245 //expect(store.getActions().type).toEqual(action.type)
@@ -42,63 +55,28 @@ describe('Fetch Signup actions', () => {
4255 // })
4356 // })
4457
45- // return store.dispatch(actions.requestSignup()).then(() => {
46- // const expectedActions = store.getActions();
47- // expect(expectedActions[0].type).toEqual('REQUEST_SIGNUP')
48- // expect(expectedActions[1].type).toEqual('REQUEST_ERROR')
49- // })
50- } , 5000 )
51-
5258 it ( 'Creates REQUEST_SUCCESS after task is successful' , ( ) => {
53- mock . onGet ( `${ URL } /user/signup` )
54- . reply ( 200 , { response :{ Message : "User M has been created. Check email for verification" } } )
55- store . dispatch ( actions . requestSignup ( ) ) . then ( ( res ) => {
56- const expectedActions = store . getActions ( )
57- expect ( expectedActions [ 0 ] . type ) . toEqual ( 'REQUEST_SIGNUP' )
58- expect ( expectedActions [ 1 ] . type ) . toEqual ( 'REQUEST_SUCCESS' )
59- //expect(store.getActions().type).toEqual(action.type)
60- } )
61- // moxios.wait(() => {
62- // const request = moxios.requests.mostRecent()
63- // request.respondWith({
64- // status: 200,
65- // response: {
66- // Message: "User M has been created. Check email for verification"
67- // }
68- // })
69- // })
59+
60+ moxios . wait ( ( ) => {
61+ const request = moxios . requests . mostRecent ( )
62+ request . respondWith ( {
63+ status : 200 ,
64+ response : {
65+ Message : "User M has been created. Check email for verification"
66+ }
67+ } )
68+ } )
7069
71- // return store.dispatch(actions.requestSignup()).then(() => {
72- // const expectedActions = store.getActions();
73- // expect(expectedActions[0].type).toEqual('REQUEST_SIGNUP')
74- // expect(expectedActions[1].type).toEqual('REQUEST_SUCCESS')
75- // })
76- } , 5000 )
70+ return store . dispatch ( actions . requestSignup ( user , nextStep ) ) . then ( ( ) => {
71+ const expectedActions = store . getActions ( ) ;
72+ expect ( expectedActions [ 0 ] . type ) . toEqual ( 'REQUEST_SIGNUP' )
73+ expect ( expectedActions [ 1 ] . type ) . toEqual ( 'REQUEST_SUCCESS' )
74+ } )
75+ } )
7776 it ( 'should dispatch the CLOSE_SNACKBAR action' , ( ) => {
7877 store . clearActions ( ) ;
7978 store . dispatch ( actions . closeSnackbar ( ) )
8079 expect ( store . getActions ( ) ) . toEqual ( [ { "type" : "CLOSE_SNACKBAR" } ] ) ;
8180 } )
8281
8382} )
84- describe ( 'signupStore(creds)' , ( ) => {
85- const store = mockStore ( { } ) ;
86- const mock = new MockAdapter ( axios ) ;
87- beforeEach ( ( ) => {
88- store . clearActions ( ) ;
89- } ) ;
90-
91- it ( 'dispatches REQUEST_SIGNUP after signup success' , ( ) => {
92- mock . onPost ( process . env . REACT_APP_BACKEND_LINK + '/user/signup' )
93- . reply ( 200 , { response :{ data :{ data :'User M has been created. Check email for verification' } } } ) ;
94- store . dispatch ( actions . requestSignup ( user ) ) . then ( ( ) => {
95- let expectedActions = [
96- { type : actions . REQUEST_SIGNUP } ,
97- { type : actions . REQUEST_SUCCESS }
98- ] ;
99- expect ( store . getActions ( ) ) . toEqual ( expectedActions ) ;
100- } ) . catch ( err => { } ) ;
101-
102- } , 50000 )
103-
104- } )
0 commit comments