我正在为我的express应用程序设置单元测试。当我运行我的测试时,它失败了,并显示以下错误
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({})
});
});发布于 2019-02-09 01:03:32
我想是你的模块系统还是捆绑器(webpack?)弄得一团糟。这在我的示例中工作得很好:https://runkit.com/fatso83/chai-spy-example
前几天我在WebKit上看到了这一点,我通过将导入拆分成两行来修复它。尝试替换
import chai, { expect } from 'chai';使用
import chai, from 'chai';
import { expect } from 'chai';https://stackoverflow.com/questions/54574912
复制相似问题