forked from wbinnssmith/smear
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
55 lines (46 loc) · 1.04 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var test = require('blue-tape');
var smear = require('./');
test('with a real Promise', function (t) {
return Promise.resolve([1, 2, 3]).then(smear(function (one, two, three) {
t.equal(one, 1);
t.equal(two, 2);
t.equal(three, 3);
}));
});
test('throws if parameter is something other than an array', function (t) {
t.plan(1);
Promise.resolve(5)
.then(smear(function (one, two, three) {}))
.catch(function (e) {
if (e.message.match(/smear/)) {
t.pass();
}
});
});
test('throws if extraneous arguments', function (t) {
t.plan(1);
function foo (fn) {
fn([1, 2, 3], 5);
}
try {
foo(smear(function (one, two, three) {}));
} catch (e) {
if (e.message.match(/smear/)) {
t.pass();
}
}
});
test('passes through the context', function (t) {
t.plan(4);
var x = {
foo: function (fn) {
fn.call(this, [5, 6, 7]);
}
};
x.foo(smear(function (five, six, seven) {
t.equal(this, x);
t.equal(five, 5);
t.equal(six, 6);
t.equal(seven, 7);
}));
});