Как можно улучшить этот следующий тест? Я чувствую, что этот код, который я только что написал, мог бы быть лучше написан.
Вот действие:
const fetchResult = auth => dispatch => {
return dispatch({
types: [FETCH_REQUEST, FETCH_SUCCESS, FETCH_FAILURE],
promise: axios({
method: 'get',
url: url,
headers: {
Authorization: `Token ${auth}`,
},
}),
});
};
А вот шутливый код для его проверки:
// some code for store declaration & fixture is not shown here
describe('The boats actions', () => {
beforeEach(() => {
// create a fresh store;
let store = reduxMockStore(appReducer);
});
const mockDispatch = f => {
// mocked the dispatch arg so it lets the func execution to carry on
let r = f(d => d);
// right now, r.promise is in 'pending' state
r.promise.then((result) => {
expect(result.data).toEqual(ExpectedFixture);
});
};
it('should match the expected signature when `fetchResults` is called', () => {
nock(API_ENDPOINT)
.get('/adminsearch/?&page=1')
.reply(200, ExpectedFixture);
mockDispatch(fetchResult('abc'));
...