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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
describe "function stub", ->
it "should create empty function", ->
stub_fn!
assert.is_true true
it "should support stub in table", ->
obj = {
stub: stub_fn!
}
assert.is_true true
it "should work with method stub", ->
obj =
method: stub_fn!
assert.is_true true
it "should handle stub in assignment", ->
my_func = stub_fn!
assert.is_true true
it "should support stub in return", ->
get_stub = -> stub_fn!
fn = get_stub!
assert.is_true true
it "should work in conditional", ->
if stub_fn!
assert.is_true true
it "should support stub as callback", ->
call_fn = (fn) -> fn!
result = call_fn stub_fn!
assert.is_true true
it "should handle stub in table literal", ->
tb = {
on_click: stub_fn!
on_hover: stub_fn!
}
assert.is_true true
it "should work with fat arrow stub", ->
obj =
value: 10
method: stub_fn!
result = obj\method!
assert.is_true true
it "should support stub in array", ->
callbacks = [stub_fn!, stub_fn!, stub_fn!]
assert.same #callbacks, 3
it "should handle stub in expression", ->
result = stub_fn! and true or false
assert.is_true result
it "should work with chained stub calls", ->
stub_fn!
stub_fn!
stub_fn!
assert.is_true true
it "should support stub in comprehension", ->
result = [stub_fn! for i = 1, 3]
assert.same #result, 3
it "should handle stub in switch", ->
value = "test"
result = switch value
when "test"
stub_fn!
"matched"
else
"not matched"
assert.same result, "matched"
it "should work in with statement", ->
obj = {stub: stub_fn!}
with obj
.stub!
assert.is_true true
it "should support stub as argument default", ->
fn = (callback = stub_fn!) ->
callback!
result = fn!
assert.is_true true
it "should handle stub in varargs", ->
collect = (...) ->
{...}
result = collect stub_fn!, stub_fn!
assert.same #result, 2
it "should work in do block", ->
do
stub_fn!
assert.is_true true
it "should support stub in try block", ->
success = try
stub_fn!
true
catch err
false
assert.is_true success
|