Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- undefined is not an object (evaluating 'store.dispatch(actionCreator.anotherSimpleAction()).then')
- import { expect } from 'chai';
- import sinon from 'sinon';
- import nock from 'nock';
- import configureMockStore from 'redux-mock-store';
- import thunk from 'redux-thunk';
- import * as actionCreator from '../SimpleActions';
- const middlewares = [thunk];
- const mockStore = configureMockStore(middlewares);
- describe('Async actions', () => {
- afterEach(() => {
- nock.cleanAll();
- });
- it('Should dispatch async action', () => {
- nock('http://jsonplaceholder.typicode.com')
- .get('/posts')
- .reply(200, { status: 200, data: 'HAHAHA' });
- const expectedActions = [
- {
- type: 'ANOTHER_SIMPLE_ACTION',
- api: { status: 200, data: 'HAHAHA' },
- },
- ];
- const store = mockStore();
- return store.dispatch(actionCreator.anotherSimpleAction())
- .then(() => {
- expect(store.getActions()).to.have.length(1);
- expect(store.getActions()).to.deep.equal(expectedActions);
- });
- });
- });
- import axios from 'axios';
- export function anotherSimpleAction() {
- return (dispatch) => {
- axios({
- method: 'get',
- url: 'http://jsonplaceholder.typicode.com/posts',
- })
- .then((response) => {
- if (response.status === 200) {
- dispatch({
- type: 'ANOTHER_SIMPLE_ACTION',
- api: response,
- });
- }
- })
- .catch((error) => {
- dispatch({
- type: 'ERROR',
- payload: error.msg,
- });
- });
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement