jam 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/jam.js DELETED
@@ -1,121 +0,0 @@
1
-
2
- // test/jam.js - Test the main JAM exports
3
- (function() {
4
-
5
- var assert = require('chai').assert
6
- , stub = require('sinon').stub;
7
-
8
-
9
- var NON_FUNCTIONS = [undefined, null, 123, 'string'];
10
-
11
- function agent() { return stub().callsArg(0); }
12
- function ident(next) { if (typeof next === 'function') return next(); }
13
-
14
-
15
- describe('JAM', function() {
16
- before(function() { this.jam = require('../index'); });
17
-
18
- describe('module', function() {
19
- it('should exports a function', function() {
20
- assert.typeOf(this.jam, 'function');
21
- });
22
- }); // module
23
-
24
- describe('function', function() {
25
- it('should throws if given something that is not a function', function() {
26
- var me = this;
27
- NON_FUNCTIONS.forEach(function(thing) {
28
- assert.throws(function() { me.jam(thing); }, /function/i);
29
- });
30
- });
31
-
32
- it('should throws if given something as a chain continuation that is not a function', function() {
33
- var me = this;
34
- NON_FUNCTIONS.forEach(function(thing) {
35
- assert.throws(function() { me.jam(ident)(thing); }, /function/i);
36
- });
37
- });
38
-
39
- it('should runs the supplied function', function(done) {
40
- this.jam(done);
41
- });
42
-
43
- it('should returns a function', function(done) {
44
- assert.typeOf(this.jam(done), 'function');
45
- });
46
-
47
- it('should supply a `next` function when chaining', function(done) {
48
- this.jam(function(next) {
49
- assert.typeOf(next, 'function');
50
- next();
51
- })(done);
52
- });
53
-
54
- it('should *not* supply `next` for the last entry in the chain', function(done) {
55
- this.jam(agent())(function(arg) {
56
- assert.isUndefined(arg);
57
- done();
58
- });
59
- });
60
-
61
- it('should runs all the supplied functions if chained', function(done) {
62
- var raccoon = agent(), rabbit = agent(), horse = agent();
63
- this.jam(raccoon)(rabbit)(horse)(function() {
64
- assert(raccoon.called);
65
- assert(rabbit.called);
66
- assert(horse.called);
67
- done();
68
- });
69
- });
70
-
71
- it('should not pass error to the last function in the chain if arguments were given to last `next` call', function(done) {
72
- this.jam(function(next) { next(null, 'one', 'two', 'three'); })
73
- (function(e) {
74
- // 'one' may accidentally be passed due to an arguments shifting bug
75
- assert.ok(!e);
76
- done();
77
- });
78
- });
79
-
80
- it('should pass error to the last function in the chain if error is given to `next`', function(done) {
81
- var e = new Error('test');
82
-
83
- this.jam(function(next) { next(e); })
84
- (function(next) { done(new Error('This function should *not* run.')); })
85
- (function(e_) {
86
- assert.equal(e, e_);
87
- done();
88
- });
89
- });
90
-
91
- it('should pass arguments to chained function if non-error arguments given to `next`', function(done) {
92
- this.jam(function(next) { next(null, 'one'); })
93
- (function(next, arg) { assert.equal(arg, 'one'); next(); })
94
- (function(next) { next(null, 'two', 'three'); })
95
- (function(next, arg0, arg1) {
96
- assert.equal(arg0, 'two');
97
- assert.equal(arg1, 'three');
98
- next();
99
- })
100
- (done);
101
- });
102
-
103
- it('should calls initial function with `this` bound to supplied context object', function(done) {
104
- this.jam(function(next) {
105
- assert.equal(this, assert);
106
- next()
107
- }, assert)(done);
108
- });
109
-
110
- it('should calls chained function with `this` bound to supplied context object', function(done) {
111
- this.jam(function(next) { next(); })
112
- (function(next) { assert.equal(this, assert); next() }, assert)
113
- (done);
114
- });
115
-
116
- }); // function
117
-
118
- });
119
-
120
- })();
121
-