Splinteer
Splinteer

Reputation: 1264

Sinon chai negative assertions not working with expect

I'm trying to use sinon-chai with expect but when I try to check if a function is not called, I get:

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

This is what I tried:

  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();

But none of them is working, but I have no problem without the ".not"

My file is starting with:

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

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

Upvotes: 0

Views: 947

Answers (2)

Seba
Seba

Reputation: 1

You can use a spy with expect:

expect(spy.called).to.be.false

Upvotes: 0

Splinteer
Splinteer

Reputation: 1264

Ok so I found that this is because of the parens. So just replace called() by called and it's working.

Upvotes: 0

Related Questions