Permalink
Browse files

test for .reset()

  • Loading branch information...
1 parent 61dd716 commit 7e492c52404efdbbb2a0dd8394b6600d6361e619 @substack committed Jan 4, 2012
Showing with 52 additions and 0 deletions.
  1. +52 −0 test/reset.js
View
@@ -0,0 +1,52 @@
+var test = require('tap').test;
+var OrderedEmitter = require('../');
+
+test('reset the order', function (t) {
+ var em = new OrderedEmitter;
+
+ var events = [
+ { order : 2 },
+ { order : 4 },
+ { order : 1 },
+ { order : 0 },
+ { order : 5 },
+ { order : 3 },
+ { order : 6 },
+ { order : 2 },
+ { order : 0 },
+ { order : 1 },
+ ];
+
+ var iv = setInterval(function () {
+ var ev = events.shift();
+ if (!ev) {
+ clearInterval(iv);
+ em.emit('end');
+ }
+ else {
+ em.emit('data', ev);
+ if (ev.order === 6) em.reset();
+ }
+ }, 5);
+
+ var order = [];
+ em.on('data', function (obj) {
+ order.push(obj);
+ });
+
+ em.on('end', function () {
+ t.deepEqual(order, [
+ { order : 0 },
+ { order : 1 },
+ { order : 2 },
+ { order : 3 },
+ { order : 4 },
+ { order : 5 },
+ { order : 6 },
+ { order : 0 },
+ { order : 1 },
+ { order : 2 },
+ ]);
+ t.end();
+ });
+});

0 comments on commit 7e492c5

Please sign in to comment.