Repository navigation
Closed
Labels
Description
Describe the bug
similar to #2677 , looks like deep equal behavior has regressed in sinon 21.0.2.
comparing stub arguments succeeds for native variables, but fails for object.
in this case, mongo sequence comparison.
To Reproduce
use the following two tests, both succeeed with sinon 21.0.1, however the first one fails in sinon 21.0.2:
describe.only('test sinon object comparison', () => {
class TestDao {
getRawObjects ({ param1, param2, seq, limit, sort }) {
const q = { param1, param2 }
if (seq) {
q.seq = { $gt: new Mongo.ObjectId(seq) }
}
this.getObjects(q, limit, sort)
}
getObjects (query, limit, sort) {
// do something
}
}
it('compares objects with sinon.assert, including mongo ObjectId conversion', () => {
const query = { param1: 'str', param2: 'foo', seq: '5feb913181428ef0bb81524a' }
const expectedQuery = {
param1: 'str',
param2: 'foo',
seq: { $gt: new Mongo.ObjectId(query.seq) }
}
const instance = new TestDao()
sinon.stub(instance, 'getObjects').resolves([])
instance.getRawObjects({ ...query, limit: 100, sort: { sort: 'desc' } })
sinon.assert.calledOnceWithExactly(instance.getObjects, expectedQuery, 100, { sort: 'desc' })
})
it('compares objects with sinon.assert', () => {
const query = { param1: 'str', param2: 'foo' }
const expectedQuery = {
param1: 'str',
param2: 'foo'
}
const instance = new TestDao()
sinon.stub(instance, 'getObjects').resolves([])
instance.getRawObjects({ ...query, limit: 100, sort: { sort: 'desc' } })
sinon.assert.calledOnceWithExactly(instance.getObjects, expectedQuery, 100, { sort: 'desc' })
})
})
Expected behavior
both tests should succeed.
Screenshots
N/A
Context (please complete the following information):
- Sinon version : 21.0.2
- Runtime:
Binaries:
Node: 24.13.1 - /usr/local/bin/node
npm: 11.8.0 - /usr/local/bin/npm
Browsers:
Chrome: 145.0.7632.160
Safari: 26.1
Reacted by Simon Nilsson
Activity
simonnilsson commentedon Mar 16, 2026
I have seen a similar issue with several tests involving Mongo ObjectId breaking from 21.0.1 to 21.0.2.
fatso83 commentedon Apr 9, 2026
I assumed this would be fixed by simply
npm iagain, after fixing this in sinonjs/samsam#291, which fixed #2678.I assume you pulled the latest version after clearing
node_modulesbefore posting a bug, so I'll verify.fatso83 commentedon Apr 9, 2026
Ah, I cannot run those tests. Please post something I can verify. Complete examples.
simonnilsson commentedon Apr 9, 2026
My issues at least seems have been fixed in 21.0.3.
fatso83 commentedon Apr 9, 2026
Perf.