使用 Mocha 进行测试并尝试使用 babel 并尝试使用 array.prototype.includes
Testing with Mocha and trying to use babel and trying to use array.prototype.includes
我正在用 Mocha 测试我的 react/redux 代码,预计我将 mocha 配置为使用 es6 ,但它似乎缺乏对 array.prototype.includes 的支持,即使我有一个 .babelrc 指定阶段-0。在我的非测试代码中,array.prototype.includes 有效。除了 babelrc 之外,是否还有一些特定于 mocha 的设置需要设置才能使用 array.prototype.includes?
这是我的package.json
{
"name": "client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha --compilers js:babel-core/register --recursive",
"test:watch": "npm test -- --watch",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.4.0",
"babel-loader": "^6.2.1",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"expect": "^1.14.0",
"lodash": "^4.0.1",
"mocha": "^2.4.5",
"react-addons-test-utils": "^0.14.7",
"react-hot-loader": "^1.3.0",
"redux-devtools": "^3.0.2",
"redux-devtools-dock-monitor": "^1.0.1",
"redux-devtools-log-monitor": "^1.0.2",
"webpack": "^1.12.11",
"webpack-dev-server": "^1.14.1"
},
"dependencies": {
"axios": "^0.8.1",
"cuid": "^1.3.8",
"history": "^1.17.0",
"lodash": "^4.0.1",
"ramda": "^0.19.1",
"react": "^0.14.6",
"react-addons-shallow-compare": "^0.14.7",
"react-dom": "^0.14.6",
"react-redux": "^4.0.6",
"react-router": "^1.0.3",
"react-router-redux": "^2.1.0",
"redux": "^3.1.7",
"redux-crud": "^0.10.1",
"redux-devtools": "^3.0.2",
"redux-devtools-dock-monitor": "^1.0.1",
"redux-devtools-log-monitor": "^1.0.2",
"redux-loop": "^1.0.2",
"redux-saga": "^0.4.1",
"redux-simple-router": "^2.0.3",
"reselect": "^2.0.3",
"seamless-immutable": "^5.0.1"
}
}
谢谢!
Array.prototype.includes
通过 babel-polyfill
提供,因为它不需要转译。看起来你的 package.json
中已经有 babel-polyfill
所以只要确保你在你的 mocha 测试中 import
ing 它。
我正在用 Mocha 测试我的 react/redux 代码,预计我将 mocha 配置为使用 es6 ,但它似乎缺乏对 array.prototype.includes 的支持,即使我有一个 .babelrc 指定阶段-0。在我的非测试代码中,array.prototype.includes 有效。除了 babelrc 之外,是否还有一些特定于 mocha 的设置需要设置才能使用 array.prototype.includes?
这是我的package.json
{
"name": "client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha --compilers js:babel-core/register --recursive",
"test:watch": "npm test -- --watch",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.4.0",
"babel-loader": "^6.2.1",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"expect": "^1.14.0",
"lodash": "^4.0.1",
"mocha": "^2.4.5",
"react-addons-test-utils": "^0.14.7",
"react-hot-loader": "^1.3.0",
"redux-devtools": "^3.0.2",
"redux-devtools-dock-monitor": "^1.0.1",
"redux-devtools-log-monitor": "^1.0.2",
"webpack": "^1.12.11",
"webpack-dev-server": "^1.14.1"
},
"dependencies": {
"axios": "^0.8.1",
"cuid": "^1.3.8",
"history": "^1.17.0",
"lodash": "^4.0.1",
"ramda": "^0.19.1",
"react": "^0.14.6",
"react-addons-shallow-compare": "^0.14.7",
"react-dom": "^0.14.6",
"react-redux": "^4.0.6",
"react-router": "^1.0.3",
"react-router-redux": "^2.1.0",
"redux": "^3.1.7",
"redux-crud": "^0.10.1",
"redux-devtools": "^3.0.2",
"redux-devtools-dock-monitor": "^1.0.1",
"redux-devtools-log-monitor": "^1.0.2",
"redux-loop": "^1.0.2",
"redux-saga": "^0.4.1",
"redux-simple-router": "^2.0.3",
"reselect": "^2.0.3",
"seamless-immutable": "^5.0.1"
}
}
谢谢!
Array.prototype.includes
通过 babel-polyfill
提供,因为它不需要转译。看起来你的 package.json
中已经有 babel-polyfill
所以只要确保你在你的 mocha 测试中 import
ing 它。