How to make a Jest of such a test reducer?

There's 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
}

Can't do the test.
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)
})
})

Produces here such error

import { NPRONE_NEAR_BY } from '../src/store/reducers/nprone';
^^^^^^

What did I do wrong?
June 14th 19 at 20:19
1 answer
June 14th 19 at 20:21
To write tests for jest with es6-the imports which does not accept the node, you need to transpalet code with babel-jest, which will be es6-imports transform into commonjs.
I have this package with the installation broke everything. don't even know how all to return back.. games! - Kelli.Nitzsche98 commented on June 14th 19 at 20:24
not hard, but jest. Describe what you have broken? - matt_Bahringer commented on June 14th 19 at 20:27
packages what installed that are not appropriate to what I use. after removing node_modules and `remove yarn babel-jest && yarn install` it worked, now will try again) - Kelli.Nitzsche98 commented on June 14th 19 at 20:30
will — don't forget to mark the question solution ;) - matt_Bahringer commented on June 14th 19 at 20:33
not working. everything is garbage. - Kelli.Nitzsche98 commented on June 14th 19 at 20:36
so let's see. What exactly doesn't work? Some acceptany can? - matt_Bahringer commented on June 14th 19 at 20:39
, package.json
"scripts": {
 "jes": "jest NODE_ENV=test",
 "jes:w": "npm run watch --jes --"
},
"dependencies": {
 "babel-preset-es2015": "^6.24.1",
},
"devDependencies": {
 "babel-jest": "^21.2.0",
 "babel-preset-es2016": "^6.24.1",
 "babel-preset-react": "^6.24.1",
}

.babelrc
{
 "presets": [["es2015", { "modules": false }], "react"],
 "env": {
 "test": {
 "plugins": [ "istanbul" ],
 "presets": [["es2015"], "react"]
}
}
}

of reducer import is. player.js I not need to import it, tried to do it without modules, but does not help `"modules": false`

eact-test.js
● Test suite failed to run

/Users/ninjamate/Documents/projects/NPROne-X1/src/store/reducers/player.js:82
var ACTION_HANDLERS = (cov_2itoyo239y.s[14]++, (_ref = {}, _defineProperty(_ref, PLAYER_TIME, function (state, action) {cov_2itoyo239y.f[7]++;cov_2itoyo239y.s[15]++;return Object.assign({}, state, { currentTime: action.payload });}), _defineProperty(_ref, PLAYER_ERROR, function (state, action) {cov_2itoyo239y.f[8]++;cov_2itoyo239y.s[16]++;return Object.assign({}, state, { currentError: action.payload });}), _defineProperty(_ref, PLAYER_STATE, function (state, action) {cov_2itoyo239y.f[9]++;cov_2itoyo239y.s[17]++;return Object.assign({}, state, { state: action.payload });}), _defineProperty(_ref, PLAYER_ON_CAN_PLAY, function (state, action) {cov_2itoyo239y.f[10]++;cov_2itoyo239y.s[18]++;return Object.assign.apply(Object, [{}, state].concat(_toConsumableArray((0, _pick2.default)(action.payload, ["]))));}), _defineProperty(_ref, PLAYER_UPDATE_CURRENTTIME, function (state, action) {cov_2itoyo239y.f[11]++;cov_2itoyo239y.s[19]++;return

SyntaxError: Unexpected token ...

at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:305:17)
at Object. (src/store/reducers/nprone.js:355:122)
at Object. (__tests__/Station.react-test.js:5:15)

- Kelli.Nitzsche98 commented on June 14th 19 at 20:42
You did everything as the instructions written in the babel-jest? - matt_Bahringer commented on June 14th 19 at 20:45
, transform-es2015-modules-commonjs
{
 "presets": [["es2015", { "modules": false }], "react"],
 "env": {
 "test": {
 "plugins": ["transform-es2015-modules-commonjs" ],
 "presets": [["es2015", { "modules": false }], "react"]
}
}
}

babel-jest not earned. - Kelli.Nitzsche98 commented on June 14th 19 at 20:48

Find more questions by tags Testing softwareReactRedux