This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
call.js
79 lines (68 loc) · 1.82 KB
/
call.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
describe('call', function() {
describe('when not given a function', function() {
it('should throw a TypeError', function() {
each(
[ 0
, 1
, []
, {}
, true
, false
, null
, undefined
]
, function(nonfn) {
expect(function() {
call(nonfn)
}).to.throw(TypeError)
}
)
})
})
describe('when given a function `fn`', function() {
describe('and no arguments', function(done) {
it('should call the function without arguments', function(done) {
var fn = function() {
expect(arguments.length).to.equal(0)
done()
}
call(fn)
})
describe('and `fn` is bound', function() {
it('should not affect the binding', function(done) {
var owner = {}
var fn = function() {
expect(arguments.length).to.equal(0)
expect(this).to.equal(owner)
done()
}
call(fn.bind(owner))
})
})
})
describe('and when given arguments', function(done) {
it('should call the function with arguments', function(done) {
var fn = function() {
expect(slice(arguments)).to.eql([1, true, 'wibble'])
done()
}
call(fn, 1, true, 'wibble')
})
describe('and `fn` is bound', function() {
it('should not affect the binding', function(done) {
var owner = {}
var fn = function() {
expect(slice(arguments)).to.eql([1, true, 'wibble'])
expect(this).to.equal(owner)
done()
}
call(fn.bind(owner), 1, true, 'wibble')
})
})
})
})
})
var expect = require('must')
, slice = require('../lib/slice')
, each = require('../lib/each')
, call = require('../lib/call')