Skip to content

Commit

Permalink
build: add more information into generic message
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed May 20, 2019
1 parent f0c4d59 commit 40b0060
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function createTypeError (message, key, value) {
}

function throwTypeError (key, value, type, message) {
if (!message || isBoolean(message)) message = `Expected {${type}} for '${key}'.`
if (!message || isBoolean(message)) message = `Expected \`${type}\` for \`${key}\`, got \`${value}\``
throw createTypeError(message, key, value)
}

Expand Down
7 changes: 2 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ describe('schema defintion', function () {
}

var validator = osom(schema)
var errMessage = "Expected {string} for 'age'."
;(function () { validator() }).should.throw(errMessage)
;(function () { validator() }).should.throw('Expected `string` for `age`, got `undefined`')
})

it('custom error message', function () {
Expand Down Expand Up @@ -133,11 +132,9 @@ describe('schema defintion', function () {
}
}

var errMessage = "Expected {string} for 'age'."
var validator = osom(schema, { casting: false })

;[{ age: 23 }].forEach(function (obj) {
;(function () { validator(obj) }).should.throw(errMessage)
;(function () { validator(obj) }).should.throw('Expected `string` for `age`, got `23`')
})
})

Expand Down

0 comments on commit 40b0060

Please sign in to comment.