Skip to content

Commit

Permalink
Jest migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
arb committed Nov 3, 2017
1 parent a61daa1 commit 38c51bf
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 105 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ lib-cov
complexity.md
.vscode
.eslintcache
package-lock.json
package-lock.json
coverage/**
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
verbose: true,
collectCoverageFrom: ['lib/index.js'],
collectCoverage: true,
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100
}
}
};
4 changes: 1 addition & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ Celebrate.errors = () => {

if (err.details) {
for (var i = 0; i < err.details.length; i++) {
// Disabling because the only way to get this is to fake the Joi response which I don't feel like doing
/* $lab:coverage:off$ */
/* istanbul ignore next */
const path = Array.isArray(err.details[i].path) ? err.details[i].path.join('.') : err.details[i].path;
/* $lab:coverage:on$ */
error.validation.keys.push(EscapeHtml(path));
}
}
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"lint": "belly-button -f",
"test": "npm run lint && lab -v -a code -p -t 100"
"lint": "belly-button -i 'lib/*.js' -f",
"test": "npm run lint && jest --ci"
},
"repository": {
"type": "git",
Expand All @@ -32,8 +32,8 @@
"devDependencies": {
"@types/express": "4.x.x",
"belly-button": "4.x.x",
"code": "4.x.x",
"lab": "14.x.x"
"expect": "21.2.x",
"jest": "21.2.x"
},
"engines": {
"node": ">=4.0.0"
Expand Down
29 changes: 29 additions & 0 deletions test/__snapshots__/celebrate.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Celebrate Middleware errors() only includes key values if joi returns details 1`] = `
Object {
"error": "Bad Request",
"message": "child \\"first\\" fails because [\\"first\\" is required]",
"statusCode": 400,
"validation": Object {
"keys": Array [],
"source": "body",
},
}
`;

exports[`Celebrate Middleware errors() responds with a joi error 1`] = `
Object {
"error": "Bad Request",
"message": "child \\"first\\" fails because [\\"first\\" is required]. child \\"last\\" fails because [\\"last\\" is required]. child \\"role\\" fails because [\\"role\\" must be a number]",
"statusCode": 400,
"validation": Object {
"keys": Array [
"first",
"last",
"role",
],
"source": "query",
},
}
`;
Loading

0 comments on commit 38c51bf

Please sign in to comment.