Answer the question
In order to leave comments, you need to log in
How to Jest test such a reducer?
There is such a reducer
export const sdk = new NPROneSDK()
// Nearby
export const NPRONE_NEAR_BY = 'nprone/NPRONE_NEARBY'
export const getNearBy = () => dispatch => {
console.info('getNearBy')
return sdk.searchStations('94708')
.then(nearBy => {
dispatch(setNearBy(nearBy))
})
.catch(e => {
onNearByError(e)
throw (e)
})
}
const setNearBy = (payload) => {
console.info('setNearBy', payload)
return {
type: NPRONE_NEAR_BY,
payload
}
}
const onNearByError = (error) => {
console.error('onNearByError', error)
}
// ------------------------------------
// Action Handlers
// ------------------------------------
const ACTION_HANDLERS = {
[NPRONE_NEAR_BY]: (state, action) => Object.assign({}, state, {nearBy: action.payload})
}
const initialState = {
nearBy: []
}
export default function nprOneReducer (state = initialState, action) {
const handler = ACTION_HANDLERS[action.type]
return handler ? handler(state, action) : state
}
import {NPRONE_NEAR_BY} from '../src/store/reducers/nprone'
import * as actions from '../src/store/reducers/nprone'
describe('actions', () => {
it('should create an action to add a todo', () => {
const expectedAction = {
type: NPRONE_NEAR_BY
}
expect(actions.getNearBy()).toEqual(expectedAction)
})
})
import { NPRONE_NEAR_BY } from '../src/store/reducers/nprone';
^^^^^^
Answer the question
In order to leave comments, you need to log in
To write tests for jest with es6 imports that the node does not accept, you need to transpile the code using babel-jest , which will turn es6 imports into commonjs.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question