Permalink
Browse files

test.empty()

  • Loading branch information...
1 parent b416578 commit 29d6d61407973520e0783a5ddb7b8e78e7846a11 @5long committed Nov 5, 2010
Showing with 13 additions and 3 deletions.
  1. +7 −0 src/assert.js
  2. +1 −1 src/test.js
  3. +5 −2 test/fixture/sample_test.js
View
@@ -51,4 +51,11 @@ module.exports = util.merge(eA, {
fail(actual, expected, msg, "!==", eA.isnt)
}
+, empty: function(val, msg) {
+ if (val === ""
+ || (val instanceof Array && !val.length)
+ || (val instanceof Object && !Object.keys(val).length)) return
+ fail(val, 0, msg, "length", eA.empty)
+ }
+
})
View
@@ -4,7 +4,7 @@ var util = require("./util")
, EventEmitter = require("events").EventEmitter
, supportedAsserts = ("ok equal notEqual deepEqual notDeepEqual"
+ " strictEqual notStrictEqual throws doesNotThrow"
- + " instanceOf typeOf length match include cb in emits is isnt"
+ + " instanceOf typeOf length match include cb in emits is isnt empty"
).split(" ")
function Test(desc, action) {
@@ -21,15 +21,18 @@ var t = new Test("a simple one", function(test) {
test.in(0, ["yep"])
test.is(42, "42", "fail")
test.isnt(0/0, NaN)
+ test.empty("")
+ test.empty([])
+ test.empty({})
})
module.exports = {
t: t
, testDesc: "a simple one"
, msg: msg
, num: {
- all: 10
- , passed: 6
+ all: 13
+ , passed: 9
, failed: 4
}
}

0 comments on commit 29d6d61

Please sign in to comment.