chai
semver
>=4.0.0 <7.0.0postconditions4functions4last verified2026-06-12coverage score67%Postconditions — what we check
- expect · expect-assertion-failurewarningWhenassertion fails (e.g., expect(value).to.equal(expected) when value !== expected)Throws
AssertionErrorRequired 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 unavailablevisibilityvisibleSources[1] - assert · assert-assertion-failurewarningWhenassertion fails (e.g., assert.equal(actual, expected) when actual !== expected)Throws
AssertionErrorRequired 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 unavailablevisibilityvisibleSources[2] - should · should-assertion-failurewarningWhenassertion fails (e.g., value.should.equal(expected) when value !== expected)Throws
AssertionErrorRequired handlingShould-style assertions throw AssertionError on failure. Primarily for test code. If used outside tests, MUST wrap in try-catch.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - assert.ifError · assert-iferror-rethrows-valuewarningWhenval 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.Throws
val (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
Every postcondition cites at least one of these. Numbered to match the footnotes above.
Need a different package?
Request a profile