reactjs - Jest fails to load moment -


i have simple react component utilizes moment library:

import react 'react'; import moment 'moment';  let { component } = react;  export class simpleapp extends component {     constructor (props) {         super(props);         var currentdate = this.props.data[this.props.current].date;          this.state = {             currentdate: currentdate,             currentfromatted: moment(currentdate).format('dddd, mmmm yyyy')         };     }      render() {         return (             <div classname="simple">{this.state.currentdate}</div>         );     } }   module.exports = simpleapp; 

and have test test component:

import react 'react/addons'; import simpleapp '../js/components/pages/simple.react';  var testutils = react.addons.testutils;   jest.dontmock('../js/components/pages/simple.react'); jest.dontmock('moment');  describe('simpleapp', () => {     it('should not anything', () => {         var data = {             "date": "2015-07-01",             "total": 2,             "results":[                 {                     "starttime": "2015-07-01t00:00:00.000",                     "endtime": "2015-07-01t00:59:59.999",                     "total": 2,                     "results":[                         {                             "type":"motion",                             "count":2                         },                         {                             "type":"transaction",                             "count":0                         }                     ]                 }             ]         };          var simple = testutils.renderintodocument(             <simpleapp data={[data]} current="0" />         );          var div = testutils.findrendereddomcomponentwithtag(simple, 'div');         expect(div.getdomnode().textcontent).toequal('2015-07-01');     }) }) 

when run npm test error says cannot call method 'format' of undefined:

● simpleapp › should not   - typeerror: cannot call method 'format' of undefined         @ new simpleapp (/users/xiaofanyang/workspace/solink/histogram/flux2/js/components/pages/simple.react.js:13:69) 

it seems moment library mocked, however, did specify not mock it... no help...

the way managed around doing

jest.automockoff();  

and manually mocking else needed in project.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -