Created
October 22, 2018 08:21
-
-
Save tiagogomes772/437eb1b8276ff573d23dee2978a5f04a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
describe('AsyncActions', () => { | |
beforeAll(() => { | |
mockStore = ReduxMockStore.default(middlewares); | |
initialState = {}; | |
}); | |
beforeEach(() => { | |
fetch.resetMocks(); | |
}); | |
it('Does a getRandomAdvice action successful', () => { | |
fetch.mockResponse(JSON.stringify({slip: { | |
advice: 'Advice' | |
}})); | |
const expectedActions = [ | |
{ type: 'REQUEST_ADVICE' }, | |
{ payload: 'Advice', type: 'RESPONSE_ADVICE_SUCCESS' }, | |
]; | |
const store = mockStore(initialState); | |
return ( | |
store.dispatch(actions.getRandomAdvice()).then(() => { | |
expect(store.getActions()).toEqual(expectedActions); | |
}) | |
); | |
}); | |
it('Does a getRandomAdvice action when the server is down', () => { | |
fetch.mockResponse(JSON.stringify({slip: { | |
advice: 'Advice' | |
}}), {status: 500}); | |
const expectedActions = [ | |
{ type: 'REQUEST_ADVICE' }, | |
{ type: 'RESPONSE_ADVICE_FAILURE' }, | |
]; | |
const store = mockStore(initialState); | |
return ( | |
store.dispatch(actions.getRandomAdvice()).then(() => { | |
expect(store.getActions()).toEqual(expectedActions); | |
}) | |
); | |
}); | |
it('Does a getRandomAdvice successful', () => { | |
fetch.mockReject(new Error()); | |
const expectedActions = [ | |
{ type: 'REQUEST_ADVICE' }, | |
{ type: 'RESPONSE_ADVICE_FAILURE' }, | |
]; | |
const store = mockStore(initialState); | |
return ( | |
store.dispatch(actions.getRandomAdvice()).then(() => { | |
expect(store.getActions()).toEqual(expectedActions); | |
}) | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment