From 0c380a063ab44f161d73a0ab6a9a7e4caaad8bbb Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 7 Oct 2014 16:49:20 +1100 Subject: [PATCH] tests: add tests for types --- test/types.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/types.js diff --git a/test/types.js b/test/types.js new file mode 100644 index 0000000..4b6c123 --- /dev/null +++ b/test/types.js @@ -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 ')) + }) + } + }) + }) + }) +})