Permalink
Browse files

Merge branch 'master' of https://github.com/bog/dnode-protocol into cull

  • Loading branch information...
substack committed Oct 3, 2011
2 parents 647b73a + a49817e commit 44b5deb5653640a287d4f99eb1e59cfccf670d68
Showing with 45 additions and 0 deletions.
  1. +1 −0 index.js
  2. +44 −0 test/store.js
View
@@ -249,6 +249,7 @@ var Store = exports.Store = function() {
};
self.get = function (id) {
+ if (!self.has(id)) return null;
return wrap(items[id]);
};
View
@@ -0,0 +1,44 @@
+var assert = require('assert');
+var Store = require('dnode-protocol').Store;
+
+exports.store = function () {
+ var s = new Store;
+
+ assert.eql(s.items.length, 0);
+
+ var i = 0;
+ var cb = function() {
+ i++;
+ };
+
+ var fn1 = function () {
+ cb();
+ };
+ s.add(fn1);
+ assert.eql(s.items.length, 1);
+ s.get(0)();
+ fn1();
+ assert.eql(i, 2);
+ assert.eql(s.items[0].times, undefined);
+
+ var fn2 = function() {
+ cb();
+ };
+ fn2.times = 2;
+ s.add(fn2);
+ assert.eql(s.items.length, 2);
+ s.get(1)();
+ fn2();
+ assert.eql(i, 4);
+ assert.eql(s.items[1].times, 1);
+ s.get(1)();
+ assert.eql(s.items[1], undefined);
+
+ var fn3 = function() {
+ cb2();
+ };
+ s.add(fn3);
+ assert.eql(s.items.length, 3);
+};
+
+

0 comments on commit 44b5deb

Please sign in to comment.