Skip to content

Commit

Permalink
[Tests] clean up throws tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 26, 2024
1 parent 5360d20 commit 9133c93
Showing 1 changed file with 48 additions and 47 deletions.
95 changes: 48 additions & 47 deletions test/throws.js
Expand Up @@ -24,20 +24,21 @@ tap.test('failures', function (tt) {
tt.plan(1);

var test = tape.createHarness();
var count = 0;
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# non functions',
'ok 1 should throw',
'ok 2 should throw',
'ok 3 should throw',
'ok 4 should throw',
'ok 5 should throw',
'ok 6 should throw',
'ok 7 should throw',
'ok 8 should throw',
'ok ' + ++count + ' should throw',
'ok ' + ++count + ' should throw',
'ok ' + ++count + ' should throw',
'ok ' + ++count + ' should throw',
'ok ' + ++count + ' should throw',
'ok ' + ++count + ' should throw',
'ok ' + ++count + ' should throw',
'ok ' + ++count + ' should throw',
'# function',
'not ok 9 should throw',
'not ok ' + ++count + ' should throw',
' ---',
' operator: throws',
' expected: undefined',
Expand All @@ -50,13 +51,13 @@ tap.test('failures', function (tt) {
' [... stack stripped ...]',
' ...',
'# custom error messages',
'ok 10 "message" is enumerable',
"ok 11 { custom: 'error', message: 'message' }",
'ok 12 getter is still the same',
'ok ' + ++count + ' "message" is enumerable',
'ok ' + ++count + ' { custom: \'error\', message: \'message\' }',
'ok ' + ++count + ' getter is still the same',
'# throws null',
'ok 13 throws null',
'ok ' + ++count + ' throws null',
'# wrong type of error',
'not ok 14 throws actual',
'not ok ' + ++count + ' throws actual',
' ---',
' operator: throws',
' expected: |-',
Expand All @@ -70,34 +71,34 @@ tap.test('failures', function (tt) {
' [... stack stripped ...]',
' ...',
'# object',
'ok 15 object properties are validated',
'ok ' + ++count + ' object properties are validated',
'# object with regexes',
'ok 16 object with regex values is validated',
'ok ' + ++count + ' object with regex values is validated',
'# similar error object',
'ok 17 throwing a similar error',
'ok ' + ++count + ' throwing a similar error',
'# validate with regex',
'ok 18 regex against toString of error',
'ok ' + ++count + ' regex against toString of error',
'# custom error validation',
'ok 19 error is SyntaxError',
'ok 20 error matches /value/',
'ok 21 unexpected error',
'ok ' + ++count + ' error is SyntaxError',
'ok ' + ++count + ' error matches /value/',
'ok ' + ++count + ' unexpected error',
'# throwing primitives',
'ok 22 primitive: null',
'ok 23 primitive: undefined',
'ok 24 primitive: 0',
'ok 25 primitive: NaN',
'ok 26 primitive: 42',
'ok 27 primitive: Infinity',
'ok 28 primitive: \'\'',
'ok 29 primitive: \'foo\'',
'ok 30 primitive: true',
'ok 31 primitive: false',
'ok ' + ++count + ' primitive: null, no expected',
'ok ' + ++count + ' primitive: undefined, no expected',
'ok ' + ++count + ' primitive: 0, no expected',
'ok ' + ++count + ' primitive: NaN, no expected',
'ok ' + ++count + ' primitive: 42, no expected',
'ok ' + ++count + ' primitive: Infinity, no expected',
'ok ' + ++count + ' primitive: \'\', no expected',
'ok ' + ++count + ' primitive: \'foo\', no expected',
'ok ' + ++count + ' primitive: true, no expected',
'ok ' + ++count + ' primitive: false, no expected',
'# ambiguous arguments',
'ok 32 Second',
'ok 33 Second',
'ok 34 Second',
'ok 35 should throw',
'not ok 36 should throw',
'ok ' + ++count + ' Second',
'ok ' + ++count + ' Second',
'ok ' + ++count + ' Second',
'ok ' + ++count + ' should throw',
'not ok ' + ++count + ' should throw',
' ---',
' operator: throws',
' expected: |-',
Expand All @@ -113,10 +114,10 @@ tap.test('failures', function (tt) {
' [... stack stripped ...]',
' ...',
'# non-extensible throw match',
'ok 37 error is non-extensible',
'ok 38 non-extensible error matches',
'ok 39 errorWithMessage is non-extensible',
'not ok 40 non-extensible error with message matches',
'ok ' + ++count + ' error is non-extensible',
'ok ' + ++count + ' non-extensible error matches',
'ok ' + ++count + ' errorWithMessage is non-extensible',
'not ok ' + ++count + ' non-extensible error with message matches',
' ---',
' operator: throws',
' expected: |-',
Expand All @@ -126,14 +127,14 @@ tap.test('failures', function (tt) {
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' ...',
'# frozen `message` property',
'ok 41 error is non-writable',
'ok 42 error is non-configurable',
'ok 43 non-writable error matches',
'ok ' + ++count + ' error is non-writable',
'ok ' + ++count + ' error is non-configurable',
'ok ' + ++count + ' non-writable error matches',
'',
'1..43',
'# tests 43',
'1..' + count,
'# tests ' + count,
'# pass 39',
'# fail 4',
'# fail ' + (count - 39),
''
]);
}));
Expand Down Expand Up @@ -281,7 +282,7 @@ tap.test('failures', function (tt) {

test('throwing primitives', function (t) {
[null, undefined, 0, NaN, 42, Infinity, '', 'foo', true, false].forEach(function (primitive) {
t.throws(function () { throw primitive; }, 'primitive: ' + inspect(primitive));
t.throws(function () { throw primitive; }, 'primitive: ' + inspect(primitive) + ', no expected');
});

t.end();
Expand Down

0 comments on commit 9133c93

Please sign in to comment.