@ -40,39 +40,6 @@ function lazyErrors() {
const assert = module . exports = ok ;
// The AssertionError is defined in assert.
// new assert.AssertionError({ message: message,
// actual: actual,
// expected: expected });
// TODO(jasnell): Consider moving AssertionError into internal/errors.js
class AssertionError extends Error {
constructor ( options ) {
if ( typeof options !== 'object' || options === null ) {
// Lazy because the errors module itself uses assertions, leading to
// a circular dependency. This can be eliminated by moving this class
// into internal/errors.js
const errors = lazyErrors ( ) ;
throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'options' , 'object' ) ;
}
const message = options . message ||
` ${ util . inspect ( options . actual ) . slice ( 0 , 128 ) } ` +
` ${ options . operator } ` +
util . inspect ( options . expected ) . slice ( 0 , 128 ) ;
super ( message ) ;
this . generatedMessage = ! options . message ;
this . name = 'AssertionError [ERR_ASSERTION]' ;
this . code = 'ERR_ASSERTION' ;
this . actual = options . actual ;
this . expected = options . expected ;
this . operator = options . operator ;
var stackStartFunction = options . stackStartFunction || fail ;
Error . captureStackTrace ( this , stackStartFunction ) ;
}
}
assert . AssertionError = AssertionError ;
// At present only the three keys mentioned above are used and
// understood by the spec. Implementations or sub modules can pass
// other keys to the AssertionError's constructor - they will be
@ -89,7 +56,8 @@ function fail(actual, expected, message, operator, stackStartFunction) {
message = actual ;
if ( arguments . length === 2 )
operator = '!=' ;
throw new AssertionError ( {
const errors = lazyErrors ( ) ;
throw new errors . AssertionError ( {
message : message ,
actual : actual ,
expected : expected ,
@ -101,6 +69,13 @@ function fail(actual, expected, message, operator, stackStartFunction) {
// EXTENSION! allows for well behaved errors defined elsewhere.
assert . fail = fail ;
// The AssertionError is defined in internal/error.
// new assert.AssertionError({ message: message,
// actual: actual,
// expected: expected });
assert . AssertionError = lazyErrors ( ) . AssertionError ;
// Pure assertion tests whether a value is truthy, as determined
// by !!guard.
// assert.ok(guard, message_opt);