Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function startSagaTester(handler, { startSaga = true } = {}) {
const sagaTester = new SagaTester({
initialState: {},
reducers: { example: (state = {}) => state },
});
function* exampleSaga() {
yield takeLatest(START_EXAMPLE, handler);
}
sagaTester.start(exampleSaga);
if (startSaga) {
sagaTester.dispatch({ type: START_EXAMPLE });
}
return sagaTester;
}
it('should correctly handle sassdocs that have a section', async () => {
const sagaTester = new SagaTester({ initialState: { sassdocs: {} } });
const data = { name: 'layovers' };
fetchSassdoc.mockImplementation(() => data);
sagaTester.start(watchSassdocRequests);
sagaTester.dispatch(sassdocRequest('layovers', 'helpers'));
sagaTester.dispatch(done());
await sagaTester.waitFor(DONE);
expect(fetchSassdoc).toBeCalledWith('helpers/layovers');
const expected = [
sassdocRequest('layovers', 'helpers'),
sassdocSuccess(['helpers', 'layovers'], data),
done(),
];
expect(sagaTester.getCalledActions()).toEqual(expected);
});
beforeEach(() => {
errorHandler = createStubErrorHandler();
mockApi = sinon.mock(api);
const { state } = dispatchSignInActions();
apiState = state.api;
sagaTester = new SagaTester({
initialState: state,
reducers: {
addons: addonsReducer,
api: apiReducer,
discoResults: discoResultsReducer,
},
});
sagaTester.start(discoSaga);
});
beforeEach(() => {
errorHandler = createStubErrorHandler();
mockApi = sinon.mock(versionsApi);
clientData = dispatchClientMetadata();
sagaTester = new SagaTester({
initialState: clientData.state,
reducers: {
api: apiReducer,
versions: versionsReducer,
},
});
sagaTester.start(versionsSaga);
});
beforeEach(() => {
errorHandler = createStubErrorHandler();
mockApi = sinon.mock(api);
const initialState = dispatchSignInActions().state;
sagaTester = new SagaTester({
initialState,
reducers: {
api: apiReducer,
autocomplete: autocompleteReducer,
},
});
sagaTester.start(autocompleteSaga);
});
beforeEach(() => {
errorHandler = createStubErrorHandler();
mockSearchApi = sinon.mock(searchApi);
const { state } = dispatchClientMetadata();
apiState = state.api;
sagaTester = new SagaTester({
initialState: state,
reducers: {
api: apiReducer,
landing: landingReducer,
},
});
sagaTester.start(landingSaga);
});
beforeEach(() => {
errorHandler = createStubErrorHandler();
mockCollectionsApi = sinon.mock(collectionsApi);
mockHeroApi = sinon.mock(heroApi);
mockSearchApi = sinon.mock(searchApi);
sagaTester = new SagaTester({
initialState: dispatchClientMetadata().state,
reducers: {
api: apiReducer,
home: homeReducer,
},
});
sagaTester.start(homeSaga);
});
beforeEach(() => {
errorHandler = createStubErrorHandler();
mockApi = sinon.mock(searchApi);
guids = ['support@lastpass.com', '{b76ed4e7-12a6-4f25-a27b-fc3f93289008}'];
const initialState = dispatchClientMetadata().state;
sagaTester = new SagaTester({
initialState,
reducers: {
api: apiReducer,
guides: addonsReducer,
},
});
sagaTester.start(guidesSaga);
});
beforeEach(() => {
const clientData = dispatchClientMetadata();
errorHandler = createStubErrorHandler();
mockApi = sinon.mock(recommendationsApi);
sagaTester = new SagaTester({
initialState: clientData.state,
reducers: {
api: apiReducer,
recommendations: recommendationsReducer,
},
});
sagaTester.start(recommendationsSaga);
});
beforeEach(() => {
errorHandler = createStubErrorHandler();
mockApi = sinon.mock(api);
const initialState = dispatchSignInActions().state;
sagaTester = new SagaTester({
initialState,
reducers: { api: apiReducer, search: searchReducer },
});
sagaTester.start(searchSaga);
});