Skip to content

Commit

Permalink
More detailed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
buschtoens committed Nov 8, 2012
1 parent e008d18 commit 6941693
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions test/typechecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var sanitize = require("../")
, argsOf = sanitize.argsOf
, argumentsOf = sanitize.argumentsOf;

// Tests
describe("typeOf(obj)", function() {
describe("String", function() {
it("should return 'String' when obj is a String", function() {
Expand All @@ -13,15 +14,30 @@ describe("typeOf(obj)", function() {
});

describe("Number", function() {
it("should return 'Number' when obj is a Number", function() {
it("should return 'Number' when obj is 0", function() {
typeOf(0).should.eql("Number");
});
it("should return 'Number' when obj is >0", function() {
typeOf(1).should.eql("Number");
});
it("should return 'Number' when obj is <0", function() {
typeOf(-1).should.eql("Number");
});
it("should return 'Number' when obj is a decimal", function() {
typeOf(1.5).should.eql("Number");
});
it("should return 'Number' when obj is a hex code", function() {
typeOf(0xFF).should.eql("Number");
});
it("should return 'Number' when obj is an exponential number", function() {
typeOf(3.45e2).should.eql("Number");
});
it("should return 'Number' when obj is NaN (Not a Number)", function() {
typeOf(NaN).should.eql("Number");
});
it("should return 'Number' when obj is Infinity", function() {
typeOf(Infinity).should.eql("Number");
typeOf(-Infinity).should.eql("Number");
});
});

Expand Down Expand Up @@ -57,35 +73,41 @@ describe("typeOf(obj)", function() {
});
});

describe("RegExp", function() {
describe("Other types", function() {
it("should return 'RegExp' when obj is a regular expression", function() {
typeOf(/.+/).should.eql("RegExp");
});
});

describe("Date", function() {
it("should return 'Date' when obj is a Date", function() {
typeOf(new Date).should.eql("Date");
});
});
});

describe("nameOf(fun)", function() {
it("should return the name of the function fun or false", function() {
it("should return the name of the function fun", function() {
nameOf(function test(a, b, c) {}).should.eql("test");
nameOf(function test (a, b, c) {}).should.eql("test");
nameOf(function test() { return 0; }).should.eql("test");
});
it("should return an empty string when fun does not have a name", function() {
nameOf(function (a, b, c) {}).should.eql("");
nameOf(function() {}).should.eql("");
nameOf(function(){}).should.eql("");
});
it("should return false when fun isn't a function", function() {
nameOf(1337).should.eql(false);
});
});

describe("argsOf(fun)", function() {
it("should return an array of the expected arguments of function fun or false", function() {
argsOf(function test(a, b, c) {}).should.eql(["a", "b", "c"]);
argsOf(function test() { return 0; }).should.eql([]);
argsOf(function (a, b, c) {}).should.eql(["a", "b", "c"]);
it("should return an empty array when the function fun doesn't expect any arguments", function() {
argsOf(function test() { return 0; }).should.eql([]);
argsOf(function() {}).should.eql([]);
});
it("should return false when fun isn't a function", function() {
argsOf(1337).should.eql(false);
});
});

0 comments on commit 6941693

Please sign in to comment.