|
1 require("../env"); |
|
2 require("../../d3"); |
|
3 |
|
4 var vows = require("vows"), |
|
5 assert = require("assert"); |
|
6 |
|
7 var suite = vows.describe("d3.rebind"); |
|
8 |
|
9 suite.addBatch({ |
|
10 "rebind": { |
|
11 topic: function() { |
|
12 return d3.rebind; |
|
13 }, |
|
14 "bound function uses object as context": function(rebind) { |
|
15 var a = {}, that, f = rebind(a, function() { that = this; }); |
|
16 assert.strictEqual((f(), that), a); |
|
17 assert.strictEqual((f.call({}), that), a); |
|
18 }, |
|
19 "bound function receives any arguments": function(rebind) { |
|
20 var a = [], b = {}, f = rebind(a, function() { a = Array.prototype.slice.call(arguments); }); |
|
21 assert.deepEqual((f(), a), []); |
|
22 assert.deepEqual((f(1), a), [1]); |
|
23 assert.deepEqual((f(null), a), [null]); |
|
24 assert.deepEqual((f(b, b, 1), a), [b, b, 1]); |
|
25 }, |
|
26 "bound function returns object if arguments": function(rebind) { |
|
27 var a = {}, f = rebind(a, function() {}); |
|
28 assert.strictEqual(f(1), a); |
|
29 assert.strictEqual(f(1, 2, 3), a); |
|
30 }, |
|
31 "bound function returns return value if no arguments": function(rebind) { |
|
32 var a = {}, f = rebind({}, function() { return a; }); |
|
33 assert.strictEqual(f(), a); |
|
34 } |
|
35 } |
|
36 }); |
|
37 |
|
38 suite.export(module); |