Skip to content

Commit

Permalink
Similarity test of null vs. an object must fail
Browse files Browse the repository at this point in the history
Fixes a throws() bug which implicitly tested for similarity against `null`
  • Loading branch information
jhs authored and isaacs committed Jan 9, 2012
1 parent 7fef5af commit a62c7ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/tap-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ function similar (a, b, message, extra) {
if (extra && extra.skip) return assert.skip(message, extra)
// test that a has all the fields in b
message = message || "should be similar"

var is_obj = assert(a, message, extra);
if(!is_obj.ok)
return is_obj;
return equivalent(selectFields(a, b), b, message, extra)
}
assert.similar = similar
Expand Down
7 changes: 5 additions & 2 deletions test/meta-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ test("meta test", { skip: false }, function (t) {
t.ifError({ message: "this is a custom error" })
t.ok(false, "false is not ok")
t.notOk(true, "true is not not ok")
t.similar(null, {}, "Null is not similar to an object, even with no keys");
t.throws(noop, "noop does not throw");
t.throws(noop, new Error("Whoops!"), "noop does not throw an Error");
t.throws(noop, {name:"MyError", message:"Whoops!"}, "noop does not throw a MyError");
t.doesNotThrow(thr0w, "thrower does throw");
t.end()

Expand All @@ -39,9 +42,9 @@ test("meta test", { skip: false }, function (t) {
t.clear()
t.ok(true, "sanity check")
t.notOk(results.ok, "not ok")
t.equal(results.tests, 22, "total test count")
t.equal(results.tests, 25, "total test count")
t.equal(results.passTotal, 16, "tests passed")
t.equal(results.fail, 6, "tests failed")
t.equal(results.fail, 9, "tests failed")
t.type(results.ok, "boolean", "ok is boolean")
t.type(results.skip, "number", "skip is number")
t.type(results, "Results", "results isa Results")
Expand Down

0 comments on commit a62c7ab

Please sign in to comment.