Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. undefined is not an object (evaluating 'store.dispatch(actionCreator.anotherSimpleAction()).then')
  2.  
  3. import { expect } from 'chai';
  4. import sinon from 'sinon';
  5. import nock from 'nock';
  6. import configureMockStore from 'redux-mock-store';
  7. import thunk from 'redux-thunk';
  8. import * as actionCreator from '../SimpleActions';
  9.  
  10. const middlewares = [thunk];
  11. const mockStore = configureMockStore(middlewares);
  12.  
  13. describe('Async actions', () => {
  14. afterEach(() => {
  15. nock.cleanAll();
  16. });
  17.  
  18. it('Should dispatch async action', () => {
  19. nock('http://jsonplaceholder.typicode.com')
  20. .get('/posts')
  21. .reply(200, { status: 200, data: 'HAHAHA' });
  22.  
  23. const expectedActions = [
  24. {
  25. type: 'ANOTHER_SIMPLE_ACTION',
  26. api: { status: 200, data: 'HAHAHA' },
  27. },
  28. ];
  29. const store = mockStore();
  30.  
  31. return store.dispatch(actionCreator.anotherSimpleAction())
  32. .then(() => {
  33. expect(store.getActions()).to.have.length(1);
  34. expect(store.getActions()).to.deep.equal(expectedActions);
  35. });
  36. });
  37. });
  38.  
  39. import axios from 'axios';
  40.  
  41. export function anotherSimpleAction() {
  42. return (dispatch) => {
  43. axios({
  44. method: 'get',
  45. url: 'http://jsonplaceholder.typicode.com/posts',
  46. })
  47. .then((response) => {
  48. if (response.status === 200) {
  49. dispatch({
  50. type: 'ANOTHER_SIMPLE_ACTION',
  51. api: response,
  52. });
  53. }
  54. })
  55. .catch((error) => {
  56. dispatch({
  57. type: 'ERROR',
  58. payload: error.msg,
  59. });
  60. });
  61. };
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement