Skip to content

Commit 6aba09b

Browse files
author
simonepri
committed
2 parents 7b3148a + 2bedd91 commit 6aba09b

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

test.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
import test from 'ava';
22
import m from '.';
33

4-
test('empty test', t => {
5-
t.is(m.thrown(), false);
4+
test('should throw InternalServer error with an invalid type', t => {
5+
const out = m.throw('a', 'An error message', 'errorno');
6+
t.is(out.body.code, 'InternalServer');
7+
t.is(out.message, 'An error message');
8+
t.is(out.body.errno, 'errorno');
9+
t.is(out.context.debug[0], 'Invalid error type provided:InternalServerError');
10+
});
11+
12+
test('should throw the correct error with a valid type', t => {
13+
const pres = m.throw('LockedError', 'Requested resource is locked', '42');
14+
t.is(pres.body.code, 'Locked');
15+
t.is(pres.message, 'Requested resource is locked');
16+
t.is(pres.body.errno, '42');
17+
t.is(pres.context.debug.length, 0);
18+
});
19+
20+
test('should contain debug information', t => {
21+
const pres = m.throw('LockedError', 'Requested resource is locked', '42', 'debugField1', 33);
22+
t.is(pres.body.code, 'Locked');
23+
t.is(pres.message, 'Requested resource is locked');
24+
t.is(pres.body.errno, '42');
25+
t.is(pres.context.debug[0], 'debugField1');
26+
t.is(pres.context.debug[1], 33);
27+
t.is(pres.context.debug.length, 2);
28+
});
29+
30+
test('should return false, if error does not exist', t => {
31+
const out = m.throw('InexistentError', 'This error does not exist', 130);
32+
t.is(m.thrown(out, 'InexistentError'), false);
33+
});
34+
35+
test('should return true, if the error exists', t => {
36+
const out = m.throw('WrongAcceptError', 'I cannot accept this', 118);
37+
t.is(m.thrown(out, 'WrongAcceptError'), true);
638
});

0 commit comments

Comments
 (0)