File tree Expand file tree Collapse file tree 2 files changed +10
-14
lines changed Expand file tree Collapse file tree 2 files changed +10
-14
lines changed Original file line number Diff line number Diff line change @@ -62,14 +62,17 @@ describe 'td.constructor', ->
62
62
63
63
describe ' being given an array of function names' , ->
64
64
Given -> @fakeConstructor = td .constructor ([' foo' , ' bar' ])
65
- Given -> @fakeInstance = new @ fakeConstructor ()
65
+ Given -> @fakeInstance = new @ fakeConstructor (' biz ' )
66
66
Then -> @fakeConstructor .prototype .foo == @fakeInstance .foo
67
+ And -> td .verify (new @ fakeConstructor (' biz' ))
67
68
And -> td .explain (@fakeInstance .foo ).isTestDouble == true
68
69
And -> td .explain (@fakeInstance .bar ).isTestDouble == true
69
- And -> @fakeConstructor .toString () == ' [test double constructor]'
70
+ And -> @fakeConstructor .toString () == ' [test double for "(unnamed constructor)" ]'
70
71
And -> @fakeInstance .toString () == ' [test double instance of constructor]'
71
72
And -> @fakeInstance .foo .toString () == ' [test double for "#foo"]'
72
73
74
+
75
+
73
76
describe ' edge case: being given a function without prototypal methods' , ->
74
77
Given -> @ boringFunc = ->
75
78
Given -> @boringFunc .foo = ->
Original file line number Diff line number Diff line change @@ -8,19 +8,12 @@ export default (typeOrNames) =>
8
8
: fakeConstructorFromNames ( typeOrNames )
9
9
10
10
var fakeConstructorFromNames = ( funcNames ) => {
11
- return _ . tap ( class TestDoubleConstructor { } , ( cls ) => {
11
+ return _ . tap ( td . function ( '(unnamed constructor)' ) , ( fakeConstructor ) => {
12
+ fakeConstructor . prototype . toString = ( ) =>
13
+ '[test double instance of constructor]'
14
+
12
15
_ . each ( funcNames , ( funcName ) => {
13
- cls . prototype [ funcName ] = tdFunction ( `#${ funcName } ` )
16
+ fakeConstructor . prototype [ funcName ] = tdFunction ( `#${ funcName } ` )
14
17
} )
15
-
16
- addToStringMethodsToFakeType ( cls )
17
18
} )
18
19
}
19
-
20
- var addToStringMethodsToFakeType = ( fakeType , name ) => {
21
- fakeType . toString = ( ) =>
22
- `[test double constructor${ name ? ` for "${ name } "` : '' } ]`
23
-
24
- fakeType . prototype . toString = ( ) =>
25
- `[test double instance of constructor${ name ? ` "${ name } "` : '' } ]`
26
- }
You can’t perform that action at this time.
0 commit comments