Tests: actions/about.js

This commit is contained in:
Alex Gleason 2020-06-09 17:22:35 -05:00
parent f71f7e4dbd
commit 628d73eb81
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -3,6 +3,7 @@ import thunk from 'redux-thunk';
import { import {
FETCH_ABOUT_PAGE_REQUEST, FETCH_ABOUT_PAGE_REQUEST,
FETCH_ABOUT_PAGE_SUCCESS, FETCH_ABOUT_PAGE_SUCCESS,
FETCH_ABOUT_PAGE_FAIL,
fetchAboutPage, fetchAboutPage,
} from '../about'; } from '../about';
import { Map as ImmutableMap } from 'immutable'; import { Map as ImmutableMap } from 'immutable';
@ -12,11 +13,12 @@ const middlewares = [thunk];
const mockStore = configureMockStore(middlewares); const mockStore = configureMockStore(middlewares);
describe('fetchAboutPage()', () => { describe('fetchAboutPage()', () => {
beforeEach(() => stubApi(mock => { it('creates the expected actions on success', () => {
mock.onGet('/instance/about/index.html').reply(200, '<h1>Hello world</h1>');
})); stubApi(mock => {
mock.onGet('/instance/about/index.html').reply(200, '<h1>Hello world</h1>');
});
it('creates the expected actions', () => {
const expectedActions = [ const expectedActions = [
{ type: FETCH_ABOUT_PAGE_REQUEST, slug: 'index' }, { type: FETCH_ABOUT_PAGE_REQUEST, slug: 'index' },
{ type: FETCH_ABOUT_PAGE_SUCCESS, slug: 'index' }, { type: FETCH_ABOUT_PAGE_SUCCESS, slug: 'index' },
@ -27,4 +29,16 @@ describe('fetchAboutPage()', () => {
expect(store.getActions()).toEqual(expectedActions); expect(store.getActions()).toEqual(expectedActions);
}); });
}); });
it('creates the expected actions on failure', () => {
const expectedActions = [
{ type: FETCH_ABOUT_PAGE_REQUEST, slug: 'asdf' },
{ type: FETCH_ABOUT_PAGE_FAIL, slug: 'asdf' },
];
const store = mockStore(ImmutableMap());
return store.dispatch(fetchAboutPage('asdf')).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
}); });