Skip to content

Instantly share code, notes, and snippets.

@abachuk
Created September 8, 2017 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abachuk/3dffc72d05f30ec71a977f317dce8b8a to your computer and use it in GitHub Desktop.
Save abachuk/3dffc72d05f30ec71a977f317dce8b8a to your computer and use it in GitHub Desktop.
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import moxios from 'moxios';
import expect from 'expect';
import * as actions from './getPosts';
import getPostsMock from '../../mocks/getPostsMock';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
describe('getPosts actions', () => {
beforeEach(function () {
moxios.install();
});
afterEach(function () {
moxios.uninstall();
});
it('creates GET_POSTS_SUCCESS after successfuly fetching postse', () => {
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 200,
response: getPostsMock,
});
});
const expectedActions = [
{ type: actions.GET_POSTS_START },
{ type: actions.GET_POSTS_SUCCESS, posts: getPostsMock },
];
const store = mockStore({ posts: {} })
return store.dispatch(actions.getPosts()).then(() => {
// return of async actions
expect(store.getActions()).toEqual(expectedActions);
});
});
});
@Mitdd9707
Copy link

Hey @abachuk What is getPostsMock? And why have you used it and you have just imported. And exactly what can share using this file

 request.respondWith({
    status: 200,
    response: getPostsMock,
 });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment