Browse files

Limit event type of Test

  • Loading branch information...
1 parent b2b4a54 commit 8a517ab034b7fac0a20a423a98021c35b98abbb8 @5long committed Dec 3, 2010
Showing with 19 additions and 2 deletions.
  1. +13 −0 src/test.js
  2. +6 −2 test/fixture/test_emit.js
View
13 src/test.js
@@ -36,6 +36,13 @@ supportedAsserts.forEach(function(name) {
}
})
+Test.events = "assert error notice start end _beforeEnd newListener"
+ .split(" ")
+ .reduce(function(set, key) {
+ set[key] = true
+ return set
+ }, {})
+
util.def(Test.prototype, {
/*
* Supposed to be called by test runner.
@@ -109,6 +116,12 @@ util.def(Test.prototype, {
this._results.push(result)
this.emit("assert", result)
}
+, emit: function(type) {
+ if (!(type in Test.events)) {
+ throw Error(".emit() is not intended to be called publicly")
+ }
+ return EventEmitter.prototype.emit.apply(this, arguments)
+ }
})
function prepareError(expected, actual, msg, operator, stackTop) {
View
8 test/fixture/test_emit.js
@@ -12,6 +12,10 @@ var asyncTest = new Test(desc, function(assert) {
}, "This should emit")
assert.emits(es, "finish")
assert.emits(es, "nope")
+
+ assert.throws(function() {
+ assert.emit(es, "misSpell")
+ })
})
process.nextTick(function() {
@@ -28,8 +32,8 @@ module.exports = {
, timeout: 15
, msg: msg
, num: {
- all: 4
- , passed: 3
+ all: 5
+ , passed: 4
, fail: 1
}
}

0 comments on commit 8a517ab

Please sign in to comment.