Permalink
Browse files

[test] wildcard-init test

  • Loading branch information...
jamesonjlee committed Jul 19, 2011
1 parent a9e11dc commit 5855499a69f59300f6b43c35281d26b168dfb3d9
Showing with 86 additions and 2 deletions.
  1. +7 −2 package.json
  2. +79 −0 test/wildcardEvents/intialize.js
View
@@ -16,8 +16,13 @@
"url": "git://github.com/hij1nx/EventEmitter2.git"
}],
"devDependencies": {
- "nodeunit": "*"
+ "nodeunit": "*",
+ "benchmark" : ">= 0.2.2"
},
"engines": ["node"],
- "main": "./lib/eventemitter2.js"
+ "main": "./lib/eventemitter2.js",
+ "scripts" : {
+ "test" : "nodeunit test/simple/* && nodeunit test/wildcardEvents/*",
+ "benchmark" : "node test/perf/benchmark-listener.js"
+ }
}
@@ -0,0 +1,79 @@
+var basicEvents = require('nodeunit').testCase;
+var lib = '../../lib/em';
+
+/////helper///////
+function setHelper (emitter, test, testName){
+ var eventNames = [
+ testName,
+ testName + '.*',
+ testName + '.ns1',
+ testName + '.ns1.ns2',
+ testName + '.ns2.*'
+ ];
+
+ for (var i = 0; i < eventNames.length; i++) {
+ emitter.on(eventNames[i], function () {
+ test.ok(true, eventNames[i] + 'has fired');
+ });
+ }
+
+ return eventNames;
+};
+
+module.exports = basicEvents({
+
+ setUp: function (callback) {
+ var EventEmitter2;
+
+ if(typeof require !== 'undefined') {
+ EventEmitter2 = require(lib).EventEmitter2;
+ }
+ else {
+ EventEmitter2 = window.EventEmitter2;
+ }
+
+ this.emitter = new EventEmitter2({
+ wildcard: true,
+ verbose: true
+ });
+ this.emitterDefault = new EventEmitter2({
+ });
+
+ callback();
+ },
+
+ tearDown: function (callback) {
+ //clean up?
+ callback();
+ },
+
+ 'intialize 1. Configuration Flags Test.': function (test) {
+ // lazy
+ var emitter = this.emitter,
+ emitterDefault = this.emitterDefault;
+
+ test.ok(!emitterDefault.wildcard, 'default .wildcard should be false');
+ test.ok(!emitterDefault.verbose, 'default .verbose should be false');
+ test.ok(emitter.wildcard, '.wildcard should be true when set');
+ test.ok(emitter.verbose, '.verbose should be true when set');
+
+ test.expect(4);
+ test.done();
+
+ },
+ 'initialize 2. creating a wildcard EE should have listenerTree.': function (test) {
+
+ var emitter = this.emitter,
+ emitterDefault = this.emitterDefault;
+
+ test.ok(emitter.listenerTree, 'listenerTree should exist');
+ test.equal(typeof emitter.listenerTree, 'object', 'listenerTree should be an Object');
+
+ test.ok(!emitterDefault.listenerTree, 'listenerTree should not exist');
+ // check the tree to be empty?
+
+ test.expect(3);
+ test.done();
+
+ },
+});

0 comments on commit 5855499

Please sign in to comment.