schedule.js
import _ from 'lodash';
import TimeHelper from '@helpers/time';
export const RESET_DATE = 'RESET_DATE';
const DEFAULT_STATES = {
startDate: TimeHelper.getMinStartDate().toDate(),
};
export default function schedule(state = DEFAULT_STATES, action) {
switch (action.type) {
case RESET_DATE: {
return {
startDate: TimeHelper.getMaxStartDate().toDate(),
};
}
}
}
export const resetDate = () => ({
type: RESET_DATE,
});
schedule.spec.js
import { expect } from 'chai';
import schedule from '../src/store/modules/schedule';
describe('schedule', () => {
it('should ', () => {
expect(schedule).to.be.instanceOf(function);
});
});
.babelrc
{
"presets": ["react-native-stage-0"]
}
npm test
$ node ./node_modules/mocha/bin/mocha --compilers js:babel-register './schedule.spec.js'
I'm trying to write unit test for redux reducer in react-native application. Since this has been working for my node.js server application, I tried same and it show errors below.
module.js:440
throw err;
^
Error: Cannot find module 'lodash'
at Function.Module._resolveFilename (module.js:438:15)
at Function.Module._load (module.js:386:25)
at Module.require (module.js:466:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/alma/Development/ltcs/src/store/modules/schedule.js:3:1)
at Module._compile (module.js:541:32)
at loader (/Users/alma/Development/ltcs/node_modules/babel-register/lib/node.js:146:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/alma/Development/ltcs/node_modules/babel-register/lib/node.js:156:7)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Module.require (module.js:466:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/alma/Development/ltcs/test/schedule.js:4:1)
at Module._compile (module.js:541:32)
at loader (/Users/alma/Development/ltcs/node_mo%
It fails as if there's no lodash from node_modules/. Since react-native's internal transpiler supports @helpers thing, it may crash at the point, but i'm not sure why it indicates lodash is missing.
Aucun commentaire:
Enregistrer un commentaire