TypeError: (0 , _chai.describe) is not a function
TypeError: (0 , _chai.describe) is not a function
当我尝试使用 mocha 执行我的反应测试时,出现以下错误:
/Users/niklaskiefer/Github/adal-fronted/test/CasesSpec.js:49
(0, _chai.describe)('Cases', function () {
^
TypeError: (0 , _chai.describe) is not a function
at Object.<anonymous> (CasesSpec.js:16:1)
at Module._compile (module.js:541:32)
at loader (/Users/niklaskiefer/Github/adal-fronted/node_modules/babel-register/lib/node.js:158:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/niklaskiefer/Github/adal-fronted/node_modules/babel-register/lib/node.js:168:7)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at /Users/niklaskiefer/Github/adal-fronted/node_modules/mocha/lib/mocha.js:220:27
at Array.forEach (native)
at Mocha.loadFiles (/Users/niklaskiefer/Github/adal-fronted/node_modules/mocha/lib/mocha.js:217:14)
测试位于test/CasesSpec:
import * as React from 'react'
import ReactDOM from 'react-dom'
import TestUtils from 'react-addons-test-utils'
import CaseActions from 'actions/CaseActions'
import CaseStore from 'stores/CaseStore'
import FilterStore from 'stores/FilterStore'
import { expect, it, before, describe } from 'chai'
import Immutable from 'immutable'
import Globals from 'config/globals'
import moment from 'moment'
var TestCases = require('./config/TestCases.js')
describe('Cases', function () {
before(function (done) {
this.timeout(1000)
// fetch all data here because
...
我使用下面的命令来执行 'npm test'
的测试
NODE_PATH=./app mocha --compilers js:babel-core/register,css:test/config/css-compiler.js --recursive --require test/config/setup.js
css-compiler.js:
function donothing () {
return null
}
require.extensions['.css'] = donothing
require.extensions['.less'] = donothing
require.extensions['.scss'] = donothing
setups.js:
// this handles setup of the fake DOM when the tests are
// run in Node
import jsdom from 'jsdom'
var FAKE_DOM_HTML = `
<html>
<body>
</body>
</html>
`
function setupFakeDOM () {
if (typeof document !== 'undefined') {
// if the fake DOM has already been set up, or
// if running in a real browser, do nothing
return
}
// setup the fake DOM environment.
//
// Note that we use the synchronous jsdom.jsdom() API
// instead of jsdom.env() because the 'document' and 'window'
// objects must be available when React is require()-d for
// the first time.
//
// If you want to do any async setup in your tests, use
// the before() and beforeEach() hooks.
global.document = jsdom.jsdom(FAKE_DOM_HTML)
global.window = document.defaultView
global.navigator = window.navigator
}
setupFakeDOM()
几周前它工作正常,我们唯一改变的是我们使用 standardJS 作为新的代码风格。我们还将 babel-core 从 6.10.4 更新到 6.11.4。我尝试了这个解决方案:Babel/Mocha: Mocha installed globally but describe() is not defined 并删除“--require”。但这只会导致没有执行任何测试
it
、before
和 describe
是 Mocha 自动添加到全局 space 的符号。因此,无需导入任何内容即可在测试中使用它们。
chai
当然跟他们没关系。所以:
import { expect } from 'chai'
当我尝试使用 mocha 执行我的反应测试时,出现以下错误:
/Users/niklaskiefer/Github/adal-fronted/test/CasesSpec.js:49
(0, _chai.describe)('Cases', function () {
^
TypeError: (0 , _chai.describe) is not a function
at Object.<anonymous> (CasesSpec.js:16:1)
at Module._compile (module.js:541:32)
at loader (/Users/niklaskiefer/Github/adal-fronted/node_modules/babel-register/lib/node.js:158:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/niklaskiefer/Github/adal-fronted/node_modules/babel-register/lib/node.js:168:7)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at /Users/niklaskiefer/Github/adal-fronted/node_modules/mocha/lib/mocha.js:220:27
at Array.forEach (native)
at Mocha.loadFiles (/Users/niklaskiefer/Github/adal-fronted/node_modules/mocha/lib/mocha.js:217:14)
测试位于test/CasesSpec:
import * as React from 'react'
import ReactDOM from 'react-dom'
import TestUtils from 'react-addons-test-utils'
import CaseActions from 'actions/CaseActions'
import CaseStore from 'stores/CaseStore'
import FilterStore from 'stores/FilterStore'
import { expect, it, before, describe } from 'chai'
import Immutable from 'immutable'
import Globals from 'config/globals'
import moment from 'moment'
var TestCases = require('./config/TestCases.js')
describe('Cases', function () {
before(function (done) {
this.timeout(1000)
// fetch all data here because
...
我使用下面的命令来执行 'npm test'
的测试NODE_PATH=./app mocha --compilers js:babel-core/register,css:test/config/css-compiler.js --recursive --require test/config/setup.js
css-compiler.js:
function donothing () {
return null
}
require.extensions['.css'] = donothing
require.extensions['.less'] = donothing
require.extensions['.scss'] = donothing
setups.js:
// this handles setup of the fake DOM when the tests are
// run in Node
import jsdom from 'jsdom'
var FAKE_DOM_HTML = `
<html>
<body>
</body>
</html>
`
function setupFakeDOM () {
if (typeof document !== 'undefined') {
// if the fake DOM has already been set up, or
// if running in a real browser, do nothing
return
}
// setup the fake DOM environment.
//
// Note that we use the synchronous jsdom.jsdom() API
// instead of jsdom.env() because the 'document' and 'window'
// objects must be available when React is require()-d for
// the first time.
//
// If you want to do any async setup in your tests, use
// the before() and beforeEach() hooks.
global.document = jsdom.jsdom(FAKE_DOM_HTML)
global.window = document.defaultView
global.navigator = window.navigator
}
setupFakeDOM()
几周前它工作正常,我们唯一改变的是我们使用 standardJS 作为新的代码风格。我们还将 babel-core 从 6.10.4 更新到 6.11.4。我尝试了这个解决方案:Babel/Mocha: Mocha installed globally but describe() is not defined 并删除“--require”。但这只会导致没有执行任何测试
it
、before
和 describe
是 Mocha 自动添加到全局 space 的符号。因此,无需导入任何内容即可在测试中使用它们。
chai
当然跟他们没关系。所以:
import { expect } from 'chai'