-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest.js
28 lines (24 loc) · 1 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import mockStore from '../../utils/asyncActionsUtils';
import createTypes from '../../creators/createTypes';
import withPreFetch from '.';
const MockService = {
fetchSomething: () => new Promise(resolve => resolve({ ok: true, data: 42 })),
fetchFailureNotFound: () => new Promise(resolve => resolve({ ok: false, problem: 'CLIENT_ERROR', status: 404 }))
};
const actions = createTypes(['FETCH', 'FETCH_SUCCESS', 'FETCH_FAILURE', 'FETCH_LOADING'], '@TEST');
describe('withPreFetch', () => {
it('Handles correctly the prefetch behavior', async () => {
const store = mockStore({});
await store.dispatch({
type: actions.FETCH,
target: 'aTarget',
service: MockService.fetchSomething,
injections: [withPreFetch(dispatch => dispatch({ type: actions.FETCH_LOADING }))]
});
const actionsDispatched = store.getActions();
expect(actionsDispatched).toEqual([
{ type: actions.FETCH_LOADING },
{ type: actions.FETCH_SUCCESS, target: 'aTarget', payload: 42 }
]);
});
});