Skip to content

Commit 2d3421c

Browse files
test: added test for assert.ok() changes
Added tests to check if any previous behaviour where instanceof was not throwing a custom error is working with the isNativeError change in assert.ok()
1 parent 4f75e07 commit 2d3421c

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

test/parallel/test-assert.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const start = 'Expected values to be strictly deep-equal:';
3838
const actExp = '+ actual - expected';
3939

4040
assert.ok(a.AssertionError.prototype instanceof Error,
41-
'a.AssertionError instanceof Error');
41+
'a.AssertionError instanceof Error');
4242

4343
assert.throws(() => a(false), a.AssertionError, 'ok(false)');
4444
assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)');
@@ -55,6 +55,52 @@ assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)');
5555
assert.ok(threw, 'Error: ok(false)');
5656
}
5757

58+
// Throw message if the message is instanceof Error.
59+
{
60+
let threw = false;
61+
const context = vm.createContext();
62+
try {
63+
const errorConstructor = vm.runInContext('Error', context);
64+
const customError = new errorConstructor('ok(false)');
65+
assert.ok(false, customError.message);
66+
} catch (e) {
67+
threw = true;
68+
assert.ok(e instanceof Error);
69+
}
70+
assert.ok(threw, 'Error: ok(false)');
71+
}
72+
73+
// Throw message if the message is instanceof TypeError.
74+
{
75+
let threw = false;
76+
const context = vm.createContext();
77+
context.TypeError = TypeError;
78+
try {
79+
const TypeErrorConstructor = vm.runInContext('TypeError', context);
80+
const customTypeError = new TypeErrorConstructor('ok(false)');
81+
assert.ok(false, customTypeError);
82+
} catch (e) {
83+
threw = true;
84+
assert.ok(e instanceof Error);
85+
}
86+
assert.ok(threw, 'TypeError: ok(false)');
87+
}
88+
89+
// Throw message if the message is instanceof SyntaxError.
90+
{
91+
let threw = false;
92+
const context = vm.createContext();
93+
context.SyntaxError = SyntaxError;
94+
try {
95+
const SyntaxErrorConstructor = vm.runInContext('SyntaxError', context);
96+
const customSyntaxError = new SyntaxErrorConstructor('ok(false)');
97+
assert.ok(false, customSyntaxError);
98+
} catch (e) {
99+
threw = true;
100+
assert.ok(e instanceof Error);
101+
}
102+
assert.ok(threw, 'SyntaxError: ok(false)');
103+
}
58104

59105
a(true);
60106
a('test', 'ok(\'test\')');

0 commit comments

Comments
 (0)