chaijs / chai

BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
https://chaijs.github.io
MIT License
8.11k stars 694 forks source link

chai-spies broken in v5.1.0 #1610

Open iampava opened 6 months ago

iampava commented 6 months ago

The following code fails when using:

import * as chai from 'chai';
import chaiSpies from 'chai-spies';

chai.use(chaiSpies);
const expect = chai.expect;

function sum(a, b) {
    return a + b;
}

const spySum = chai.spy(sum);

expect(spySum).to.have.been.called.exactly(0);

The error is: TypeError: chai.spy is not a function


However, if I downgrade to v4.3.10 and use CJS with the following code:

const chai = require('chai');
const chaiSpies = require('chai-spies');

chai.use(chaiSpies);
const expect = chai.expect;

function sum(a, b) {
    return a + b;
}

const spySum = chai.spy(sum);

expect(spySum).to.have.been.called.exactly(0);

It works.

43081j commented 6 months ago

this is most likely caused by #1569

you can do:

import * as chaiModule from 'chai';

const chai = chaiModule.use(chaiSpies);