forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes.error.cause.js
53 lines (41 loc) · 2.39 KB
/
es.error.cause.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { PROTO } from '../helpers/constants';
import path from 'core-js-pure/es/error';
import create from 'core-js-pure/es/object/create';
function runErrorTestCase($Error, ERROR_NAME, WEB_ASSEMBLY) {
QUnit.test(`${ ERROR_NAME } constructor with 'cause' param`, assert => {
assert.isFunction($Error);
assert.arity($Error, 1);
assert.name($Error, ERROR_NAME);
if (PROTO && $Error !== path.Error) {
// eslint-disable-next-line no-prototype-builtins -- safe
assert.true(path.Error.isPrototypeOf($Error), 'constructor has `Error` in the prototype chain');
}
assert.true($Error(1) instanceof $Error, 'no cause, without new');
assert.true(new $Error(1) instanceof $Error, 'no cause, with new');
assert.true($Error(1, {}) instanceof $Error, 'with options, without new');
assert.true(new $Error(1, {}) instanceof $Error, 'with options, with new');
assert.true($Error(1, 'foo') instanceof $Error, 'non-object options, without new');
assert.true(new $Error(1, 'foo') instanceof $Error, 'non-object options, with new');
assert.same($Error(1, { cause: 7 }).cause, 7, 'cause, without new');
assert.same(new $Error(1, { cause: 7 }).cause, 7, 'cause, with new');
assert.same($Error(1, create({ cause: 7 })).cause, 7, 'prototype cause, without new');
assert.same(new $Error(1, create({ cause: 7 })).cause, 7, 'prototype cause, with new');
let error = $Error(1, { cause: 7 });
if (!WEB_ASSEMBLY) assert.same(error.name, ERROR_NAME, 'instance name');
assert.same(error.message, '1', 'instance message');
assert.same(error.cause, 7, 'instance cause');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.true(error.hasOwnProperty('cause'), 'cause is own');
error = $Error();
assert.same(error.message, '', 'default instance message');
assert.same(error.cause, undefined, 'default instance cause undefined');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.false(error.hasOwnProperty('cause'), 'default instance cause missed');
});
}
for (const ERROR_NAME of ['Error', 'EvalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError']) {
runErrorTestCase(path[ERROR_NAME], ERROR_NAME);
}
if (path.WebAssembly) for (const ERROR_NAME of ['CompileError', 'LinkError', 'RuntimeError']) {
if (path.WebAssembly[ERROR_NAME]) runErrorTestCase(path.WebAssembly[ERROR_NAME], ERROR_NAME, true);
}