Profiles·Public

chai

semver>=4.0.0 <7.0.0postconditions4functions4last verified2026-06-12coverage score67%

Postconditions — what we check

  • expect · expect-assertion-failure
    warning
    Whenassertion fails (e.g., expect(value).to.equal(expected) when value !== expected)
    ThrowsAssertionError
    Required handlingAssertions are EXPECTED to throw in test code, but if used outside tests (e.g., in production validation), callers MUST wrap in try-catch. Without error handling, failed assertions crash the application. Use pattern: try { expect(value).to.equal(expected); } catch (error) { /* handle */ }
    costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[1]
  • assert · assert-assertion-failure
    warning
    Whenassertion fails (e.g., assert.equal(actual, expected) when actual !== expected)
    ThrowsAssertionError
    Required handlingAssert-style assertions throw AssertionError on failure. In test code, this is expected. If used in production code, MUST wrap in try-catch to prevent crashes.
    costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[2]
  • should · should-assertion-failure
    warning
    Whenassertion fails (e.g., value.should.equal(expected) when value !== expected)
    ThrowsAssertionError
    Required handlingShould-style assertions throw AssertionError on failure. Primarily for test code. If used outside tests, MUST wrap in try-catch.
    costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[1]
  • assert.ifError · assert-iferror-rethrows-value
    warning
    Whenval is truthy (non-null, non-undefined, non-zero, non-false, non-empty-string). Common usage: assert.ifError(err) in callback-style code where err is an Error. Throws val directly — NOT wrapped in AssertionError.
    Throwsval (the original value passed — typically an Error, but any truthy value)
    Required handlingWhen assert.ifError(err) is used in production code (not test code), the caller must catch the rethrown error with the correct type. A catch block that expects AssertionError will NOT catch errors from assert.ifError — it rethrows the original value as-is. Correct pattern for production use: try { assert.ifError(err); // rethrows err if err is truthy } catch (e) { // e is err itself, not an AssertionError console.error('Callback error:', e.message); throw e; } Note: In test code, assert.ifError is typically called at the top of a callback to fail the test immediately if err is present. The rethrow causes test frameworks to mark the test as failed.
    costmediumin prodsilent failureusers seeservice unavailablevisibilitysilent
    Sources[3][2]

Sources

Every postcondition cites at least one of these. Numbered to match the footnotes above.

  1. [1]chaijs.com/api/bddhttps://www.chaijs.com/api/bdd/
  2. [2]chaijs.com/api/asserthttps://www.chaijs.com/api/assert/
  3. [3]chaijs.com/api/asserthttps://www.chaijs.com/api/assert/#method_iferror
Need a different package?
Request a profile