Skip to content

Commit

Permalink
Update cause tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed May 6, 2022
1 parent 6f6102f commit 016bfcc
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,29 @@ test('should serialize nested errors', t => {

const serialized = serializeError(error);
t.is(serialized.message, 'outer error');
t.is(serialized.innerError.message, 'inner error');
t.like(serialized.innerError, {
name: 'Error',
message: 'inner error',
});
t.false(serialized.innerError instanceof Error);
});

test('should serialize the cause property', t => {
const error = new Error('outer error');
error.cause = new Error('inner error');
// TODO: Replace with plain `new Error('outer', {cause: new Error('inner')})` when targeting Node 16.9+
Object.defineProperty(error, 'cause', {
value: new Error('inner error'),
enumerable: false,
writable: true,
});

const serialized = serializeError(error);
t.is(serialized.message, 'outer error');
t.is(serialized.cause.message, 'inner error');
t.like(serialized.cause, {
name: 'Error',
message: 'inner error',
});
t.false(serialized.cause instanceof Error);
});

test('should handle top-level null values', t => {
Expand Down

0 comments on commit 016bfcc

Please sign in to comment.