获取无效的Chai属性:“ drawnWith”

时间:2019-02-07 13:52:07

标签: typescript express sinon chai sinon-chai

我正在为我的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({})

    });
});

1 个答案:

答案 0 :(得分:0)

我认为这是您的模块系统或捆绑器(webpack?)弄乱了它。在我的示例中,这很好用: https://runkit.com/fatso83/chai-spy-example

前几天,我自己用WebKit看到了这一点,并通过将导入分为两行来解决了这一问题。尝试更换

import chai, { expect } from 'chai';

import chai, from 'chai';
import { expect } from 'chai';