Last active
April 30, 2017 00:15
-
-
Save DanCassiano/ed3a8285f7a92f9d283560fbf1d54f01 to your computer and use it in GitHub Desktop.
Actions tests
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
import configureMockStore from 'redux-mock-store'; | |
import nock from 'nock'; | |
import thunk from 'redux-thunk'; | |
import * as actions from './../action'; | |
import * as types from './../types'; | |
const middlewares = [ thunk ]; | |
const mockStore = configureMockStore(middlewares); | |
describe('#submitForm', () => { | |
afterEach(() => { | |
nock.cleanAll(); | |
}); | |
const mock = { | |
name: "jose", | |
email: "[email protected]", | |
telefone: "24 9999 9999", | |
msg: "Mensagem" | |
}; | |
const url = 'http://localhost:3004'; | |
it('submitForm success', () => { | |
const msg = 'Enviado com sucesso'; | |
nock(url) | |
.post("/contact", mock) | |
.reply(200, {}) | |
const expectedActions = [ | |
{ type: types.TRY_SUBMIT }, | |
{ type: types.SUBMIT_SUCCESS, msg } | |
]; | |
const store = mockStore({}); | |
return store.dispatch(actions.submitForm(mock)) | |
.then(() => { | |
expect(store.getActions()).toEqual(expectedActions); | |
}); | |
}); | |
it('submitForm failure', () => { | |
const msg = "Erro ao enviar"; | |
nock(url) | |
.post(`/42`, {}) | |
.reply(500, { msg }); | |
const expectedActions = [ | |
{ type: types.TRY_SUBMIT }, | |
{ type: types.SUBMIT_FAILURE, msg } | |
]; | |
const store = mockStore({}); | |
return store.dispatch(actions.submitForm(mock)) | |
.then(() => { | |
expect(store.getActions()).toEqual(expectedActions); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment