Permalink
Browse files

test to make sure the correct number of wraps fire

  • Loading branch information...
1 parent 4897504 commit 7cbb08bbcd317acccc62707d74421965c9acfc1d @substack committed Jun 20, 2012
Showing with 87 additions and 0 deletions.
  1. +87 −0 test/wrap.js
View
@@ -0,0 +1,87 @@
+var test = require('tap').test;
+var proto = require('../');
+var traverse = require('traverse');
+
+test('proto hashes', function (t) {
+ t.plan(8);
+ var pending = 5;
+
+ var times = { s : 0, c : 0 };
+ function done () {
+ t.same(times.s, 1); // x(f,g)
+: t.same(times.c, 2); // f, g
+ t.end();
+ }
+
+ function swrapper (fn) {
+ // 1 of these
+ t.equal(typeof fn, 'function');
+ times.s ++;
+ if (--pending === 0) done();
+ }
+
+ function cwrapper (fn) {
+ // 2 of these
+ t.equal(typeof fn, 'function');
+ times.c ++;
+ if (--pending === 0) done();
+ }
+
+ var s = proto({
+ x : function (f, g) {
+ setTimeout(f.bind({}, 7, 8, 9), 25);
+ setTimeout(g.bind({}, [ 'q', 'r' ]), 50);
+ },
+ y : 555
+ }, { wrapper : swrapper });
+
+ var c = proto({}, { wrapper : cwrapper });
+
+ var sreqs = [];
+ s.on('request', function (req) {
+ sreqs.push(traverse.clone(req));
+ c.handle(req);
+ });
+
+ var creqs = [];
+ c.on('request', function (req) {
+ creqs.push(traverse.clone(req));
+ s.handle(req);
+ });
+
+ s.start();
+
+ t.deepEqual(sreqs, [ {
+ method : 'methods',
+ arguments : [ { x : '[Function]', y : 555 } ],
+ callbacks : { 0 : [ '0', 'x' ] },
+ links : [],
+ } ]);
+
+ c.start();
+
+ t.deepEqual(creqs, [ {
+ method : 'methods',
+ arguments : [ {} ],
+ callbacks : {},
+ links : [],
+ } ]);
+
+ c.request('x', [
+ function (x, y , z) {
+ t.deepEqual([ x, y, z ], [ 7, 8, 9 ]);
+ if (--pending === 0) done();
+ },
+ function (qr) {
+ t.deepEqual(qr, [ 'q', 'r' ]);
+ if (--pending === 0) done();
+ }
+ ]);
+
+ t.deepEqual(creqs.slice(1), [ {
+ method : 'x',
+ arguments : [ '[Function]', '[Function]' ],
+ callbacks : { 0 : [ '0' ], 1 : [ '1' ] },
+ links : [],
+ } ]);
+});

0 comments on commit 7cbb08b

Please sign in to comment.