Skip to content

Commit

Permalink
stringify-error: improve stringify unit tests
Browse files Browse the repository at this point in the history
Add tests to check if strinfigy can handle error object
  • Loading branch information
vitorabner committed Jul 17, 2017
1 parent 8ba9104 commit e5d2870
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/unit/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const winston = require('winston')
const { test } = require('ava')
const utils = require('../../src/utils')

test('parseStringToJSON: with a valid JSON string', t => (
test('parseStringToJSON: with a valid JSON string', t => (
utils.parseStringToJSON(JSON.stringify({ name: 'Papyrus' }))
.then(result => t.deepEqual(result, { name: 'Papyrus' }))
))
Expand All @@ -22,6 +22,14 @@ test('stringify: with a invalid JSON object', t => {
t.is(utils.stringify('Papyrus'), 'Papyrus')
})

test('stringify: with a valid error object', t => {
const error = new Error('Error Message')
const { message, stack } = JSON.parse(utils.stringify(error))

t.is(message, 'Error Message')
t.true(stack.includes('Error: Error Message'))
})

test('generateLogLevel: with status code 400', t => {
t.is(utils.generateLogLevel(400), 'warn')
})
Expand Down

0 comments on commit e5d2870

Please sign in to comment.