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.15k stars 698 forks source link

Buffer is not recognized as an object #1541

Closed mirayashi closed 1 year ago

mirayashi commented 1 year ago

Let the following test:

const buf = Buffer.alloc(0)
expect(buf).to.be.an('object')

Expected result: the test should pass because expect(typeof buf).to.equal('object') does

Actual result: it fails

chai version 4.3.9

keithamus commented 1 year ago

.to.be.an effectively checks the Symbol.toStringTag of the object. If you want to assert on the typeof, then you should use expect(typeof buf).to.equal('object').

I'll close this as it's not a bug within chai, it's working as intended.