I'm recently learning Redux and writing Unit Test as part of TDD process using Jest
Im writing test for action creators and reducers. But i'm struggling with: can I make use of action creators in the reducers test?
import * as types from './../../constants/auth';
import * as actions from './../../actions/auth';
import reducer, {initialState} from './../auth';
can I do this
it('it should set isFetching to true', () => {
const expectedState = {
...initialState,
isFetching: true
}
expect(
reducer(initialState, actions.loginPending())
).toEqual(expectedState)
});
instead of this?
it('it should set isFetching to true', () => {
const expectedState = {
...initialState,
isFetching: true
}
expect(
reducer(initialState, {type: types.LOGIN_PENDING})
).toEqual(expectedState)
});
I came to this doubt because the official documentation use hard coded action in the reducers test:
expect(
reducer([], {
type: types.ADD_TODO,
text: 'Run the tests'
})
).toEqual([{
text: 'Run the tests',
completed: false,
id: 0
}])
I guess using hard coded actions is the best practice isn't?
Aucun commentaire:
Enregistrer un commentaire