I'm using https://github.com/mxstbr/react-boilerplate and want to mock and spy on my imports for unit tests. I have imported babel-plugin-rewire as dev dependency in my package.json
"babel-plugin-rewire": "^1.0.0",
I have also added babel-plugin-rewire as a test plugin
"test": {
"plugins": [
"istanbul","babel-plugin-rewire"
]
}
In my babel.test part in package.json.
And finally in my webpack.test.babel.js I have added
loader: 'babel?plugins=babel-plugin-rewire',
Then when I run
npm run test
I get a weird error saying
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
TypeError: undefined is not an object (evaluating 'cov_1uiq851gv7.b[1][0]')
at webpack:///app/reducers.js:36:4 <- test-bundler.js:51890
What have I missed? Has someone setup react-boilerplate with babel-plugin-rewire ?
The weird part is that reducers.js which gives there error ar excluded in my test.bundler.js Adding reducers.js
import { combineReducers } from 'redux-immutable';
import { fromJS } from 'immutable';
import { LOCATION_CHANGE } from 'react-router-redux';
import languageProviderReducer from 'containers/LanguageProvider/reducer';
import driverReducer from 'containers/DriverList/reducer';
import vehicleReducer from 'containers/VehicleList/reducer';
// Initial routing state
const routeInitialState = fromJS({
locationBeforeTransitions: null,
});
function routeReducer(state = routeInitialState, action) {
switch (action.type) {
/* istanbul ignore next */
case LOCATION_CHANGE:
return state.merge({
locationBeforeTransitions: action.payload,
});
default:
return state;
}
}
export default function createReducer(asyncReducers) {
return combineReducers({
route: routeReducer,
driverList: driverReducer,
vehicleList: vehicleReducer,
language: languageProviderReducer,
...asyncReducers,
});
}