@pvorona/assert
v0.0.1
Published
## Features
Readme
Assert
Features
- Accepts optional message or message getter/factory. Message getter/factory is only evaluated when assertion fails.
expect(assert(false, 'Message')).toThrow('Message')
expect(assert(false, () => 'Lazy message')).toThrow('Lazy Message')- Excludes itself from the stack trace.
// File example.ts
function example() {
assert(false)
}
// Throws the following stack trace
// AssertionError
// example.ts:2:3- Optionally allows passing in function from which stack trace should be captured if environment supports
Error.captureStackTrace.
// File example.ts
function example1() {
return example2()
}
function example2() {
assert(false, 'Example error message', example2) // Exclude example2 from stack trace
}
// Throws the following stack trace
// AssertionError
// example.ts:2:3