Lines Matching refs:assert
26 const assert = require('assert'); constant
30 const a = assert;
42 assert.ok(a.AssertionError.prototype instanceof Error,
45 assert.throws(() => a(false), a.AssertionError, 'ok(false)');
46 assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)');
52 assert.ok(false, new Error('ok(false)'));
55 assert.ok(e instanceof Error);
57 assert.ok(threw, 'Error: ok(false)');
66 assert.throws(() => a.equal(true, false),
76 assert.throws(() => a.notEqual(true, true),
79 assert.throws(() => a.strictEqual(2, '2'),
83 assert.throws(() => a.strictEqual(null, undefined),
86 assert.throws(
94 assert.throws(
103 assert.throws(
119 assert.throws(() => thrower(a.AssertionError), a.AssertionError, 'message');
120 assert.throws(() => thrower(a.AssertionError), a.AssertionError);
121 assert.throws(() => thrower(a.AssertionError));
124 assert.throws(() => thrower(TypeError));
127 assert.throws(
148 assert.ok(e instanceof TypeError);
150 assert(threw, 'a.doesNotThrow with an explicit error is eating extra errors');
160 assert.ok(e instanceof a.AssertionError);
161 assert.ok(!e.stack.includes('at Function.doesNotThrow'));
163 assert.ok(threw, 'a.doesNotThrow is not catching type matching errors');
166 assert.throws(
177 assert.throws(
185 assert.throws(
200 assert.throws(
209 assert.ok(threw, 'wrong constructor validation');
245 assert.throws(
250 assert.throws(() => {
256 assert.strictEqual(
261 assert.strictEqual(err.actual, actual);
270 assert.throws(
280 assert.throws(
289 assert.throws(
298 assert.throws(
312 assert.ok(e instanceof a.AssertionError);
313 assert.ok(!e.stack.includes('at Function.throws'));
315 assert.ok(threw);
322 assert.throws(
323 () => assert.strictEqual(actual, ''),
364 assert.throws(
365 () => assert.strictEqual(1, 2),
372 assert.throws(
373 () => assert.strictEqual(1, 2, 'oh no'),
386 assert.strictEqual(1, 2, rangeError);
388 assert.strictEqual(e, rangeError);
390 assert.ok(e instanceof RangeError, 'Incorrect error type thrown');
392 assert.ok(threw);
402 assert.ok(e.message.includes(rangeError.message));
403 assert.ok(e instanceof assert.AssertionError);
404 assert.ok(!e.stack.includes('doesNotThrow'), e);
406 assert.ok(threw);
412 assert.throws(
423 testBlockTypeError(assert.throws, 'string');
424 testBlockTypeError(assert.doesNotThrow, 'string');
425 testBlockTypeError(assert.throws, 1);
426 testBlockTypeError(assert.doesNotThrow, 1);
427 testBlockTypeError(assert.throws, true);
428 testBlockTypeError(assert.doesNotThrow, true);
429 testBlockTypeError(assert.throws, false);
430 testBlockTypeError(assert.doesNotThrow, false);
431 testBlockTypeError(assert.throws, []);
432 testBlockTypeError(assert.doesNotThrow, []);
433 testBlockTypeError(assert.throws, {});
434 testBlockTypeError(assert.doesNotThrow, {});
435 testBlockTypeError(assert.throws, /foo/);
436 testBlockTypeError(assert.doesNotThrow, /foo/);
437 testBlockTypeError(assert.throws, null);
438 testBlockTypeError(assert.doesNotThrow, null);
439 testBlockTypeError(assert.throws, undefined);
440 testBlockTypeError(assert.doesNotThrow, undefined);
445 assert.throws(() => { throw 'error'; }, (err) => err === 'error');
446 assert.throws(() => { throw new Error(); }, (err) => err instanceof Error);
449 assert.throws(() => {
450 assert.strictEqual('A'.repeat(1000), '');
452 assert.strictEqual(err.code, 'ERR_ASSERTION');
453 assert.strictEqual(err.message,
456 assert.strictEqual(err.actual.length, 1000);
457 assert.ok(inspect(err).includes(`actual: '${'A'.repeat(488)}...'`));
464 assert.throws(() => {
465 assert.strictEqual(multilineString, '');
467 assert.strictEqual(err.code, 'ERR_ASSERTION');
468 assert.strictEqual(err.message.split('\n').length, 19);
469 assert.strictEqual(err.actual.split('\n').length, 16);
470 assert.ok(inspect(err).includes(
482 assert.throws(
483 () => new assert.AssertionError(input),
493 assert.throws(
494 () => assert.strictEqual(new Error('foo'), new Error('foobar')),
513 const assert = require('assert').strict; constant
515 assert.throws(() => assert.equal(1, true), assert.AssertionError);
516 assert.notEqual(0, false);
517 assert.throws(() => assert.deepEqual(1, true), assert.AssertionError);
518 assert.notDeepEqual(0, false);
519 assert.equal(assert.strict, assert.strict.strict);
520 assert.equal(assert.equal, assert.strictEqual);
521 assert.equal(assert.deepEqual, assert.deepStrictEqual);
522 assert.equal(assert.notEqual, assert.notStrictEqual);
523 assert.equal(assert.notDeepEqual, assert.notDeepStrictEqual);
524 assert.equal(Object.keys(assert).length, Object.keys(a).length);
525 assert(7);
526 assert.throws(
527 () => assert(...[]),
534 assert.throws(
545 assert.throws(
547 assert.ok(
553 constructor: assert.AssertionError,
577 assert.throws(
578 () => assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]),
597 assert.throws(
598 () => assert.deepEqual(
618 assert.throws(
619 () => assert.deepEqual(
639 assert.throws(
640 () => assert.deepEqual(
656 assert.throws(
657 () => assert.deepEqual([1, 2, 1], undefined),
670 assert.throws(
671 () => assert.deepEqual([1, 2, 1], [2, 1]),
682 assert.throws(
683 () => assert.deepEqual(Array(28).fill(1), Array(28).fill(2)),
690 assert.throws(() => assert.deepEqual(obj1, obj2), {
702 assert.throws(
703 () => assert.notDeepEqual([1], [1]),
713 assert.throws(
714 () => assert.notDeepEqual(data, data),
719 assert.throws(
720 () => assert.ok(null),
723 constructor: assert.AssertionError,
729 assert.throws(
735 try { assert.ok(0); // eslint-disable-line no-useless-catch, brace-style
742 constructor: assert.AssertionError,
748 assert.throws(
756 } catch (err) { assert.ok(0); } // eslint-disable-line no-unused-vars
760 constructor: assert.AssertionError,
766 assert.throws(
772 function test() { assert.ok(0); // eslint-disable-line brace-style
778 constructor: assert.AssertionError,
784 assert.throws(
785 () => assert(typeof 123n === 'string'),
788 constructor: assert.AssertionError,
795 assert.throws(
796 () => assert(false, Symbol('foo')),
799 constructor: assert.AssertionError,
811 assert(
815 assert.throws(
819 constructor: assert.AssertionError,
824 assert.throws(
828 constructor: assert.AssertionError,
836 assert.throws(
848 constructor: assert.AssertionError,
860 assert.throws(
872 constructor: assert.AssertionError,
885 assert.throws(() => {
893 constructor: assert.AssertionError,
904 assert.throws(
906 assert(true); assert(null, undefined);
910 constructor: assert.AssertionError,
916 assert.throws(
918 assert
923 constructor: assert.AssertionError,
929 assert.throws(
931 () => assert['ok']["apply"](null, [0]),
934 constructor: assert.AssertionError,
940 assert.throws(
943 wrapper(assert, false);
947 constructor: assert.AssertionError,
952 assert.throws(
953 () => assert.ok.call(null, 0),
956 constructor: assert.AssertionError,
963 assert.throws(
964 () => assert.ok.call(null, 0, 'test'),
967 constructor: assert.AssertionError,
974 assert.throws(
975 () => new Function('assert', 'assert(1 === 2);')(assert),
978 constructor: assert.AssertionError,
982 assert.throws(
990 assert.throws(
991 () => assert.throws(() => {}, 'Error message', 'message'),
1006 assert.throws(
1007 () => assert.throws(() => {}, input),
1019 assert.throws(() => {
1020 assert.ok((() => Boolean('' === false))());
1035 assert.throws(errFn, errObj);
1038 assert.throws(errFn, errObj);
1043 assert.throws(
1044 () => assert.throws(errFn, errObj),
1060 assert.throws(
1061 () => assert.throws(errFn, errObj),
1076 assert.throws(
1077 () => assert.throws(() => { throw new Error(); }, { foo: 'bar' }, 'foobar'),
1079 constructor: assert.AssertionError,
1085 assert.throws(
1095 assert.throws(() => { throw new Error('e'); }, new Error('e'));
1096 assert.throws(
1097 () => assert.throws(() => { throw new TypeError('e'); }, new Error('e')),
1109 assert.throws(
1110 () => assert.throws(() => { throw new Error('foo'); }, new Error('')),
1125 assert.throws(() => { throw undefined; }, /undefined/);
1126 assert.throws(
1137 assert.throws(
1138 () => assert.throws(() => { throw new Error(); }, {}),
1145 assert.throws(
1158 assert.throws(
1173 assert.throws(() => { throw null; }, 'foo');
1175 assert.throws(
1176 () => assert.strictEqual([], []),
1184 assert.throws(
1185 () => assert.strictEqual(args, { 0: 'a' }),
1194 assert.throws(
1202 assert.throws(
1203 () => assert.throws(
1223 assert.throws(
1224 () => assert.throws(
1243 assert.throws(
1244 () => assert.throws(
1259 assert.throws(
1260 () => assert.strictEqual('test test', 'test foobar'),
1273 assert.throws(
1276 assert.notStrictEqual(obj, obj);
1285 assert.throws(
1288 assert.notStrictEqual(obj, obj);
1302 assert.deepStrictEqual(Array(100).fill(1), 'foobar');
1305 assert.match(inspect(err), /actual: \[Array],\n {2}expected: 'foobar',/);
1307 assert(threw);
1310 assert.throws(
1315 assert.throws(
1320 assert.throws(
1325 assert.throws(
1330 assert.throws(
1335 assert.throws(
1340 assert.throws(
1345 assert.throws(
1350 assert.throws(
1355 assert.throws(
1363 const err = new assert.AssertionError({
1368 const err2 = new assert.AssertionError({
1373 assert(!err.stack.includes('hidden'));
1374 assert(!err2.stack.includes('hidden'));
1378 assert.throws(
1379 () => assert.throws(() => { throw Symbol('foo'); }, RangeError),
1386 assert.throws(
1388 () => assert.throws(() => { throw [1, 2]; }, RangeError),
1398 assert.throws(
1399 () => assert.throws(() => { throw err; }, validate),
1413 assert.throws(
1418 assert.throws(() => { throw err; }, RangeError);
1429 assert.throws(
1430 () => assert.match(/abc/, 'string'),
1437 assert.throws(
1438 () => assert.match('string', /abc/),
1448 assert.throws(
1449 () => assert.match('string', /abc/, 'foobar'),
1459 assert.throws(
1460 () => assert.match('string', /abc/, errorMessage),
1463 assert.throws(
1464 () => assert.match({ abc: 123 }, /abc/),
1474 assert.match('I will pass', /pass$/);
1479 assert.throws(
1480 () => assert.doesNotMatch(/abc/, 'string'),
1487 assert.throws(
1488 () => assert.doesNotMatch('string', /string/),
1498 assert.throws(
1499 () => assert.doesNotMatch('string', /string/, 'foobar'),
1509 assert.throws(
1510 () => assert.doesNotMatch('string', /string/, errorMessage),
1513 assert.throws(
1514 () => assert.doesNotMatch({ abc: 123 }, /abc/),
1524 assert.doesNotMatch('I will pass', /different$/);
1529 assert.throws(() => {
1532 assert.strictEqual(111554n, 11111115);
1534 assert.strictEqual(inspect(err).split('\n')[5], ' ^');