我正在为我的快递应用程序设置的单元测试。当我运行我的测试失败,此错误``
import * as timestamp from './timestamp'
import chai, { expect } from 'chai'
import sinonChai from 'sinon-chai'
import { mockReq, mockRes } from 'sinon-express-mock'
//chai.use(sinonChai); <-- `I removed this because it was creating this error:: TypeError: Cannot read property 'use' of undefined`
describe('hello world', () => {
it('should behave...', () => {
const request = {
body: {
foo: 'bar',
},
}
const req = mockReq(request)
const res = mockRes()
timestamp.timestamp(req, res)
expect(res.json).to.have.been.calledWith({})
});
});
我认为这是你的模块系统或捆绑(的WebPack?)搞乱它。这在我的例子能正常工作:https://runkit.com/fatso83/chai-spy-example
我这个与WebKit的看到自己有一天,我通过了两行分裂进口固定它。尝试更换
import chai, { expect } from 'chai';
同
import chai, from 'chai';
import { expect } from 'chai';