use*_*695 2 javascript unit-testing mocha.js chai
为什么我TypeError: expect is not a function在运行此测试文件时会得到一个?
我在本地安装了mocha和chai并运行测试,通过yarn run test它运行简单"test": "mocha".
var chai = require('chai')
var expect = chai.expect()
describe('Array', function () {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
expect([1, 2, 3].indexOf(4)).to.be.equal(-1)
})
})
})
Run Code Online (Sandbox Code Playgroud)
设置时expect,您需要这样做:
var expect = chai.expect
Run Code Online (Sandbox Code Playgroud)
您正在评估函数(),根据文档不正确