source: imaps-frontend/node_modules/object-inspect/test/err.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[d565449]1var test = require('tape');
2var ErrorWithCause = require('error-cause/Error');
3
4var inspect = require('../');
5
6test('type error', function (t) {
7 t.plan(1);
8 var aerr = new TypeError();
9 aerr.foo = 555;
10 aerr.bar = [1, 2, 3];
11
12 var berr = new TypeError('tuv');
13 berr.baz = 555;
14
15 var cerr = new SyntaxError();
16 cerr.message = 'whoa';
17 cerr['a-b'] = 5;
18
19 var withCause = new ErrorWithCause('foo', { cause: 'bar' });
20 var withCausePlus = new ErrorWithCause('foo', { cause: 'bar' });
21 withCausePlus.foo = 'bar';
22 var withUndefinedCause = new ErrorWithCause('foo', { cause: undefined });
23 var withEnumerableCause = new Error('foo');
24 withEnumerableCause.cause = 'bar';
25
26 var obj = [
27 new TypeError(),
28 new TypeError('xxx'),
29 aerr,
30 berr,
31 cerr,
32 withCause,
33 withCausePlus,
34 withUndefinedCause,
35 withEnumerableCause
36 ];
37 t.equal(inspect(obj), '[ ' + [
38 '[TypeError]',
39 '[TypeError: xxx]',
40 '{ [TypeError] foo: 555, bar: [ 1, 2, 3 ] }',
41 '{ [TypeError: tuv] baz: 555 }',
42 '{ [SyntaxError: whoa] message: \'whoa\', \'a-b\': 5 }',
43 'cause' in Error.prototype ? '[Error: foo]' : '{ [Error: foo] [cause]: \'bar\' }',
44 '{ [Error: foo] ' + ('cause' in Error.prototype ? '' : '[cause]: \'bar\', ') + 'foo: \'bar\' }',
45 'cause' in Error.prototype ? '[Error: foo]' : '{ [Error: foo] [cause]: undefined }',
46 '{ [Error: foo] cause: \'bar\' }'
47 ].join(', ') + ' ]');
48});
Note: See TracBrowser for help on using the repository browser.