1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5 6common.expectWarning( 7 'DeprecationWarning', 8 'assert.fail() with more than one argument is deprecated. ' + 9 'Please use assert.strictEqual() instead or only pass a message.', 10 'DEP0094' 11); 12 13// Two args only, operator defaults to '!=' 14assert.throws(() => { 15 assert.fail('first', 'second'); 16}, { 17 code: 'ERR_ASSERTION', 18 name: 'AssertionError', 19 message: '\'first\' != \'second\'', 20 operator: '!=', 21 actual: 'first', 22 expected: 'second', 23 generatedMessage: true 24}); 25 26// Three args 27assert.throws(() => { 28 assert.fail('ignored', 'ignored', 'another custom message'); 29}, { 30 code: 'ERR_ASSERTION', 31 name: 'AssertionError', 32 message: 'another custom message', 33 operator: 'fail', 34 actual: 'ignored', 35 expected: 'ignored', 36 generatedMessage: false 37}); 38 39// Three args with custom Error 40assert.throws(() => { 41 assert.fail(typeof 1, 'object', new TypeError('another custom message')); 42}, { 43 name: 'TypeError', 44 message: 'another custom message' 45}); 46 47// No third arg (but a fourth arg) 48assert.throws(() => { 49 assert.fail('first', 'second', undefined, 'operator'); 50}, { 51 code: 'ERR_ASSERTION', 52 name: 'AssertionError', 53 message: '\'first\' operator \'second\'', 54 operator: 'operator', 55 actual: 'first', 56 expected: 'second' 57}); 58 59// The stackFrameFunction should exclude the foo frame 60assert.throws( 61 function foo() { assert.fail('first', 'second', 'message', '!==', foo); }, 62 (err) => !/^\s*at\sfoo\b/m.test(err.stack) 63); 64