Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('Stage AFTER_SUCCESS', (done) => {
const afterSuccess = {
_runAfterSuccess(dispatch, getState, data) {
return dispatch({type: 'foo', data});
}
};
const spy = mock.spyOn(afterSuccess, '_runAfterSuccess');
const configOptions = {
processors: {
[PROCESSOR_STAGE.AFTER_SUCCESS]: afterSuccess._runAfterSuccess
}
};
// Under test
store
.dispatch(loadEntity(entity, Promise.resolve({}), configOptions))
.then(() => {
expect(spy).toHaveBeenCalled();
})
.then(done)
.catch(done);
});
it('Stage BEFORE_SUCCESS', (done) => {
const beforeSuccess = {
_runBeforeSuccess(dispatch, getState, data) {
return dispatch({type: 'foo', data});
}
};
const spy = mock.spyOn(beforeSuccess, '_runBeforeSuccess');
const configOptions = {
processors: {
[PROCESSOR_STAGE.BEFORE_SUCCESS]: beforeSuccess._runBeforeSuccess
}
};
// Under test
store
.dispatch(loadEntity(entity, Promise.resolve({}), configOptions))
.then(() => {
expect(spy).toHaveBeenCalled();
})
.then(done)
.catch(done);
});
it('Stage BEFORE_FAILURE', (done) => {
const beforeFailure = {
_runBeforeFailure(dispatch, getState, data) {
return dispatch({type: 'foo', data});
}
};
const spy = mock.spyOn(beforeFailure, '_runBeforeFailure');
const configOptions = {
processors: {
[PROCESSOR_STAGE.BEFORE_FAILURE]: beforeFailure._runBeforeFailure
}
};
// Under test
store
.dispatch(loadEntity(entity, Promise.reject(new Error('Fake error')), configOptions))
.catch(() => {
expect(spy).toHaveBeenCalled();
done();
});
});
it('Stage BEFORE_FAILURE should return a new object', (done) => {
it('Stage AFTER_FAILURE', (done) => {
const afterFailure = {
_runAfterFailure(dispatch, getState, data) {
return dispatch({type: 'foo', data});
}
};
const spy = mock.spyOn(afterFailure, '_runAfterFailure');
const configOptions = {
processors: {
[PROCESSOR_STAGE.BEFORE_FAILURE]: afterFailure._runAfterFailure
}
};
// Under test
store
.dispatch(loadEntity(entity, Promise.reject(new Error('Fake Error')), configOptions))
.catch(() => {
expect(spy).toHaveBeenCalled();
done();
});
});
});