Skip to content

Commit

Permalink
exclude inner field if no inner error provided
Browse files Browse the repository at this point in the history
The undefined inner field can result in bogus assertion failures
when writing tests using this error-strategy.
  • Loading branch information
mpareja committed Jul 5, 2019
1 parent d8560df commit f33cf57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ for (let { type, code } of errors) {
module.exports[type] = (msg, inner) => {
const error = new Error(msg)
error.code = code
error.inner = inner
if (inner) {
error.inner = inner
}
return error
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/grpc-error-strategy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,10 @@ function testError ({ type, code }) {
const error = GrpcErrorStrategy[type](A_DESCRIPTION, inner)
expect(error.inner).toBe(inner)
})

it('excludes inner key if none provider', () => {
const error = GrpcErrorStrategy[type](A_DESCRIPTION)
expect(error).not.toHaveProperty('inner')
})
})
}

0 comments on commit f33cf57

Please sign in to comment.