summaryrefslogtreecommitdiff
path: root/test/parallel/test-errors-aborterror.js
blob: 15da9f06f94b4d558f9df29fde4a6d7b4b7f6a32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Flags: --expose-internals
'use strict';

require('../common');
const {
  strictEqual,
  throws,
} = require('assert');
const { AbortError } = require('internal/errors');

{
  const err = new AbortError();
  strictEqual(err.message, 'The operation was aborted');
  strictEqual(err.cause, undefined);
}

{
  const cause = new Error('boom');
  const err = new AbortError('bang', { cause });
  strictEqual(err.message, 'bang');
  strictEqual(err.cause, cause);
}

{
  throws(() => new AbortError('', false), {
    code: 'ERR_INVALID_ARG_TYPE'
  });
  throws(() => new AbortError('', ''), {
    code: 'ERR_INVALID_ARG_TYPE'
  });
}