File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,26 @@ store = require('./store')
3
3
calls = require (' ./store/calls' )
4
4
stubbings = require (' ./store/stubbings' )
5
5
6
- module .exports = (name ) ->
6
+ module .exports = (nameOrType ) ->
7
+ if nameOrType ? .prototype ?
8
+ createTestDoublesForEntireType (nameOrType)
9
+ else
10
+ createTestDouble (nameOrType)
11
+
12
+ createTestDouble = (name ) ->
7
13
_ .tap createTestDoubleFunction (), (testDouble ) ->
8
14
if name? then store .for (testDouble).name = name
9
15
10
16
createTestDoubleFunction = ->
11
17
testDouble = (args ... ) ->
12
18
calls .log (testDouble, args, this )
13
19
stubbings .get (testDouble, args)
20
+
21
+ createTestDoublesForEntireType = (type ) ->
22
+ _ .reduce Object .getOwnPropertyNames (type .prototype ), (memo , name ) ->
23
+ memo[name] = if _ .isFunction (type .prototype [name])
24
+ createTestDouble (" #{ type .name } ##{ name} " )
25
+ else
26
+ type .prototype [name]
27
+ memo
28
+ , {}
Original file line number Diff line number Diff line change @@ -34,6 +34,16 @@ describe '.verify', ->
34
34
When -> @result = (shouldThrow => @ verify (@ testDouble ()))
35
35
Then -> expect (@result ).to .contain (" verification on test double `#footime`." )
36
36
37
+ context ' with a prototype-modeling double' , ->
38
+ Given -> @SomeType = ` function Foo () {}`
39
+ Given -> @SomeType :: bar = ->
40
+ Given -> @SomeType :: baz = ->
41
+ Given -> @SomeType :: biz = " not a function!"
42
+ Given -> @testDoubleObj = @ create (@SomeType )
43
+ When -> @result = (shouldThrow => @ verify (@testDoubleObj .baz ()))
44
+ Then -> expect (@result ).to .contain (" verification on test double `Foo#baz`." )
45
+ Then -> @testDoubleObj .biz == " not a function!"
46
+
37
47
context ' a double-free verification error' , ->
38
48
Then -> shouldThrow (=> @ verify ()), """
39
49
No test double invocation detected for `verify()`.
You can’t perform that action at this time.
0 commit comments