Skip to content

Commit

Permalink
fix: tests and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
evanshortiss committed Jun 27, 2019
1 parent dbb2682 commit 9f1a160
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
19 changes: 13 additions & 6 deletions example/typescript/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

import * as Joi from '@hapi/joi'
import { ValidatedRequest, ValidatedRequestSchema, createValidator } from '../../express-joi-validation'
import { Router } from 'express';
import {
ValidatedRequest,
ValidatedRequestSchema,
createValidator
} from '../../express-joi-validation'
import { Router } from 'express'
import 'joi-extract-type'

const route = Router()
Expand All @@ -14,8 +17,12 @@ interface HelloRequestSchema extends ValidatedRequestSchema {
query: Joi.extractType<typeof querySchema>
}

route.get('/hello', validator.query(querySchema), (req: ValidatedRequest<HelloRequestSchema>, res) => {
res.end(`Hello ${req.query.name}`)
})
route.get(
'/hello',
validator.query(querySchema),
(req: ValidatedRequest<HelloRequestSchema>, res) => {
res.end(`Hello ${req.query.name}`)
}
)

export = route
2 changes: 1 addition & 1 deletion example/typescript/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const port = 3030
import * as express from 'express'
import * as Joi from '@hapi/joi'
import * as HelloWorld from './route'
import { createValidator } from '../../express-joi-validation';
import { createValidator } from '../../express-joi-validation'

const app = express()
const validator = createValidator()
Expand Down
6 changes: 4 additions & 2 deletions express-joi-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ function buildErrorString(err, container) {
return ret
}

module.exports = function () {
throw new Error('express-joi-validation: exported member is no longer a factory function. use exported createValidator function instead')
module.exports = function() {
throw new Error(
'express-joi-validation: exported member is no longer a factory function. use exported createValidator function instead'
)
}

module.exports.createValidator = function generateJoiMiddlewareInstance(cfg) {
Expand Down
6 changes: 3 additions & 3 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('express joi', function() {
.required()
})

mod = require('./express-joi-validation.js')()
mod = require('./express-joi-validation.js').createValidator()
})

describe('#headers', function() {
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('express joi', function() {

describe('optional configs', function() {
it('should call next on error via config.passError', function(done) {
const mod = require('./express-joi-validation.js')({
const mod = require('./express-joi-validation.js').createValidator({
passError: true
})
const mw = mod.query(
Expand Down Expand Up @@ -300,7 +300,7 @@ describe('express joi', function() {
}
resStub.status = sinon.stub().returns(resStub)

const mod = require('./express-joi-validation.js')({
const mod = require('./express-joi-validation.js').createValidator({
joi: joiStub,
statusCode: statusCode
})
Expand Down

0 comments on commit 9f1a160

Please sign in to comment.