The previous approach did avoid a fair number of jest.mock calls, but made debugging the tests harder. If you don't know about the mapping it's unclear why the imported module does not behave as normal. By forcing the use of jest.mock it means that the answer to that question is in the test you are working on.
65 lines
1.6 KiB
JavaScript
65 lines
1.6 KiB
JavaScript
/* global expect jest */
|
|
|
|
import { Subject } from 'rxjs';
|
|
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
import failedUpdatesEpic from './failed-updates-epic';
|
|
import { types } from './';
|
|
import store from 'store';
|
|
|
|
jest.mock('../analytics');
|
|
|
|
const key = 'fcc-failed-updates';
|
|
|
|
describe('failed-updates-epic', () => {
|
|
it('should remove faulty backend challenges from localStorage', async () => {
|
|
store.set(key, failedSubmissions);
|
|
|
|
const action$ = ActionsObservable.of({
|
|
type: types.updateComplete
|
|
});
|
|
const state$ = new StateObservable(new Subject(), initialState);
|
|
const epic$ = failedUpdatesEpic(action$, state$);
|
|
|
|
await epic$.toPromise();
|
|
|
|
expect(store.get(key)).toEqual(submitableChallenges);
|
|
});
|
|
});
|
|
|
|
const initialState = {
|
|
app: {
|
|
isOnline: true,
|
|
appUsername: 'developmentuser'
|
|
}
|
|
};
|
|
|
|
const failedSubmissions = [
|
|
{
|
|
endpoint: '/project-completed',
|
|
id: 'b1507944-7310-479f-bb59-ccafac488592',
|
|
payload: { id: '587d8249367417b2b2512c41', challengeType: 4 }
|
|
},
|
|
{
|
|
endpoint: '/project-completed',
|
|
id: 'b1507944-7310-479f-bb59-ccafac488593',
|
|
payload: {
|
|
id: '587d8249367417b2b2512c42',
|
|
challengeType: 4,
|
|
solution: 'http://freecodecamp.org/',
|
|
githubLink: 'https://github.com/'
|
|
}
|
|
},
|
|
{
|
|
endpoint: '/project-completed',
|
|
id: 'b1507944-7310-479f-bb59-ccafac488594',
|
|
payload: {
|
|
id: '587d8249367417b2b2512c43',
|
|
challengeType: 4,
|
|
solution: 'http://freecodecamp.org/',
|
|
githubLink: 'https://github.com/'
|
|
}
|
|
}
|
|
];
|
|
|
|
const submitableChallenges = failedSubmissions.slice(1);
|