Skip to content

Commit a38774a

Browse files
committed
add tests
1 parent 4c32125 commit a38774a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/index.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,36 @@ test('Create error with different base', (t) => {
138138
t.assert.ok(err.stack)
139139
})
140140

141+
test('Create error with different base (no stack)', (t) => {
142+
t.plan(7)
143+
144+
createError.captureStackTrace = false
145+
const NewError = createError('CODE', 'hey %s', 500, TypeError)
146+
const err = new NewError('dude')
147+
t.assert.ok(err instanceof Error)
148+
t.assert.ok(err instanceof TypeError)
149+
t.assert.equal(err.name, 'FastifyError')
150+
t.assert.equal(err.message, 'hey dude')
151+
t.assert.equal(err.code, 'CODE')
152+
t.assert.equal(err.statusCode, 500)
153+
t.assert.equal(err.stack, undefined)
154+
createError.captureStackTrace = true
155+
})
156+
157+
test('Create error with different base (no stack)', (t) => {
158+
t.plan(7)
159+
160+
const NewError = createError('CODE', 'hey %s', 500, TypeError, false)
161+
const err = new NewError('dude')
162+
t.assert.ok(err instanceof Error)
163+
t.assert.ok(err instanceof TypeError)
164+
t.assert.equal(err.name, 'FastifyError')
165+
t.assert.equal(err.message, 'hey dude')
166+
t.assert.equal(err.code, 'CODE')
167+
t.assert.equal(err.statusCode, 500)
168+
t.assert.equal(err.stack, undefined)
169+
})
170+
141171
test('FastifyError.toString returns code', (t) => {
142172
t.plan(1)
143173

0 commit comments

Comments
 (0)