Permalink
Browse files

adding test for store

  • Loading branch information...
1 parent 55a9e6f commit a49817e5188870a1d0b70471e51b285c55ad7c96 @bog bog committed Oct 2, 2011
Showing with 44 additions and 0 deletions.
  1. +44 −0 test/store.js
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 a49817e

Please sign in to comment.