Skip to content

🐛 Bug: thrown error .expected with null prototype throws TypeError: value.toString is not a function #5505

@alxndrsn

Description

@alxndrsn

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

Test should fail.

Actual

Suite stops mid-way, returning status code zero.

Minimal, Reproducible Example

package.json

{
  "name": "mocha-bug",
  "packageManager": "yarn@4.9.2",
  "devDependencies": {
    "chai": "^6.2.0",
    "mocha": "^11.7.4"
  },
  "volta": {
    "node": "24.10.0"
  }
}

test.js

const { assert } = require('chai');

describe('deepEqual()', () => {
  const o = { a:true };

  describe('sync', () => {
    it('should not equal null', () => { assert.deepEqual(o, null); });
    it('should not equal plain object', () => { assert.deepEqual(o, {}); });
    it('should not equal null-prototyped', () => { assert.deepEqual(o, Object.create(null)); });
  });

  describe('async', () => {
    it('should not equal null', async () => { assert.deepEqual(o, null); });
    it('should not equal plain object', async () => { assert.deepEqual(o, {}); });
    it('should not equal null-prototyped', async () => { assert.deepEqual(o, Object.create(null)); });
  });
});

execute:

$ yarn mocha test.js 


  deepEqual()
    sync
      1) should not equal null
      2) should not equal plain object
      3) should not equal null-prototyped
    async
      4) should not equal null
      5) should not equal plain object
$ echo $?
0

Versions

node 24.10.0
chai 6.2.0
mocha 11.7.4

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: in triagea maintainer should (re-)triage (review) this issuetype: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions