tests: add tests for types
This commit is contained in:
parent
deaf06b350
commit
0c380a063a
1 changed files with 28 additions and 0 deletions
28
test/types.js
Normal file
28
test/types.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
var assert = require('assert')
|
||||
var enforceType = require('../src/types')
|
||||
|
||||
function CustomType() {}
|
||||
|
||||
var types = ['Array', 'Boolean', 'Buffer', 'Number', 'String', CustomType]
|
||||
var values = [[], true, new Buffer(1), 1234, 'foobar', new CustomType()]
|
||||
|
||||
describe('enforceType', function() {
|
||||
types.forEach(function(type, i) {
|
||||
describe(type, function() {
|
||||
values.forEach(function(value, j) {
|
||||
if (j === i) {
|
||||
it('passes for ' + types[j], function() {
|
||||
enforceType(type, value)
|
||||
})
|
||||
|
||||
} else {
|
||||
it('fails for ' + types[j], function() {
|
||||
assert.throws(function() {
|
||||
enforceType(type, value)
|
||||
}, new RegExp('Expected ' + (type.name || type) + ', got '))
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue