下面是package.json
中脚本部分的'test'"test": "mocha tests/test.js --compilers js:babel-core/register --recursive",
以下是tests / test.js的源代码。
// Mocking window and document object:
require('./dom-mock')('<html><body></body></html>');
var jsdom = require('mocha-jsdom');
var assert = require('assert');
var React = require('react');
var TestUtils = require('react-addons-test-utils');
describe('Testing my div', function() {
jsdom({ skipWindowCheck: true });
it('should contain text: Lovely! Here it is - my very first React component!', function() {
var VeryFirstDiv = require('../source/containers/Component.js');
var myDiv = TestUtils.renderIntoDocument(
<VeryFirstDiv />
);
var divText = TestUtils.findRenderedDOMComponentWithTag(
myDiv, 'span');
assert.equal(divText.textContent, 'Lovely! Here it is - my very first React component!');
});
});
然后我运行'npm test'。打印出以下错误。
Testing my div
1) should contain text: Lovely! Here it is - my very first React component!
0 passing (50ms)
1 failing
1) Testing my div should contain text: Lovely! Here it is - my very first Reac
t component!:
Error: locals[0] does not appear to be a `module` object with Hot Module re
placement API enabled. You should disable react-transform-hmr in production by u
sing `env` section in Babel configuration. See the example in README: https://gi
thub.com/gaearon/react-transform-hmr
at Object.proxyReactComponents [as default] (C:\Users\e587214\Documents\wo
rkspace\SSC_CDT3_UI\ui\node_modules\react-transform-hmr\lib\index.js:51:11)
at Object.<anonymous> (C:\Users\e587214\Documents\workspace\SSC_CDT3_UI\ui
\source\containers\Component.js:15:60)
at normalLoader (C:\Users\e587214\Documents\workspace\SSC_CDT3_UI\ui\node_
modules\babel-core\lib\api\register\node.js:199:5)
at Object.require.extensions.(anonymous function) [as .js] (C:\Users\e5872
14\Documents\workspace\SSC_CDT3_UI\ui\node_modules\babel-core\lib\api\register\n
ode.js:216:7)
at require (internal/module.js:12:17)
at Context.<anonymous> (C:/Users/e587214/Documents/workspace/SSC_CDT3_UI/u
i/tests/test.js:13:24)
at callFn (C:\Users\e587214\Documents\workspace\SSC_CDT3_UI\ui\node_module
s\mocha\lib\runnable.js:315:21)
at Test.Runnable.run (C:\Users\e587214\Documents\workspace\SSC_CDT3_UI\ui\
node_modules\mocha\lib\runnable.js:308:7)
at Runner.runTest (C:\Users\e587214\Documents\workspace\SSC_CDT3_UI\ui\nod
e_modules\mocha\lib\runner.js:422:10)
at C:\Users\e587214\Documents\workspace\SSC_CDT3_UI\ui\node_modules\mocha\
lib\runner.js:533:12
at next (C:\Users\e587214\Documents\workspace\SSC_CDT3_UI\ui\node_modules\
mocha\lib\runner.js:342:14)
at C:\Users\e587214\Documents\workspace\SSC_CDT3_UI\ui\node_modules\mocha\
lib\runner.js:352:7
at next (C:\Users\e587214\Documents\workspace\SSC_CDT3_UI\ui\node_modules\
mocha\lib\runner.js:284:14)
at Immediate._onImmediate (C:\Users\e587214\Documents\workspace\SSC_CDT3_U
I\ui\node_modules\mocha\lib\runner.js:320:5)
我想如果这个错误与mocha或babal版本之后的参数' js:babel-core / register '有关。以下是我的package.json的一部分。
"devDependencies": {
"babel": "^5.8.29",
"babel-core": "^5.8.33",
"babel-eslint": "^4.1.3",
"babel-loader": "^5.3.2",
"babel-plugin-react-transform": "^2.0.2",
"chai": "^3.4.0",
"jsdom": "^7.0.2",
"mocha": "^2.3.3",
"mocha-jsdom": "^1.0.0",
"path-parse": "^1.0.5",
"phantomjs": "^1.9.18"
}
}