union_types.test.js (543B)
1 var assert = require('assert'); 2 var typed = require('../typed-function'); 3 4 describe('union types', function () { 5 6 it('should create a typed function with union types', function() { 7 var fn = typed({ 8 'number | boolean': function (arg) { 9 return typeof arg; 10 } 11 }); 12 13 assert.equal(fn(true), 'boolean'); 14 assert.equal(fn(2), 'number'); 15 assert.throws(function () {fn('string')}, /TypeError: Unexpected type of argument in function unnamed \(expected: number or boolean, actual: string, index: 0\)/); 16 }); 17 18 });