【问题标题】:Sinon chai negative assertions not working with expectSinon chai 否定断言不适用于期望
【发布时间】:2022-01-23 19:19:24
【问题描述】:

我正在尝试将 sinon-chai 与 expect 一起使用,但是当我尝试检查是否未调用函数时,我得到:

TypeError: expect(...).to.have.not.been.called is not a function

这是我尝试过的:

  expect(createCompany).not.to.have.been.called();
  expect(createCompany).to.not.have.been.called();
  expect(createCompany).to.have.not.been.called();
  expect(createCompany).to.have.been.not.called();
  expect(createCompany).to.have.been.notCalled();

但是它们都不起作用,但是没有“.not”我没有问题

我的文件开始于:

const chai = require('chai');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');

chai.use(sinonChai);
const { expect } = chai;

【问题讨论】:

    标签: mocha.js sinon sinon-chai


    【解决方案1】:

    好的,所以我发现这是因为括号。 因此,只需将 called() 替换为 called 即可。

    【讨论】:

      猜你喜欢
      • 2017-03-04
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      • 2017-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多