收到无效柴属性:“calledWith”

问题描述 投票:0回答:1

我正在为我的快递应用程序设置的单元测试。当我运行我的测试失败,此错误``

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({})

    });
});
typescript express sinon chai sinon-chai
1个回答
0
投票

我认为这是你的模块系统或捆绑(的WebPack?)搞乱它。这在我的例子能正常工作:https://runkit.com/fatso83/chai-spy-example

我这个与WebKit的看到自己有一天,我通过了两行分裂进口固定它。尝试更换

import chai, { expect } from 'chai';

import chai, from 'chai';
import { expect } from 'chai';
© www.soinside.com 2019 - 2024. All rights reserved.