Skip to content

Bug in stub parameter matching #2679

@rlsf

Description

@rlsf

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions