@@ -130,16 +130,27 @@ export class FunctionState implements ContextState {
130130 }
131131 }
132132
133- if ( property === SubstituteMethods . returns ) {
133+ if ( property === SubstituteMethods . returns
134+ || property === SubstituteMethods . resolves
135+ || property === SubstituteMethods . rejects
136+ ) {
134137 return ( ...returns : any [ ] ) => {
135138 if ( ! this . _lastArgs ) {
136139 throw SubstituteException . generic ( 'Eh, there\'s a bug, no args recorded for this return :/' )
137140 }
138- this . returns . push ( {
139- returnValues : returns ,
140- returnIndex : 0 ,
141- args : this . _lastArgs
142- } )
141+ const returnMock : Partial < ReturnMock > = { returnIndex : 0 , args : this . _lastArgs } ;
142+ switch ( property ) {
143+ case SubstituteMethods . returns :
144+ returnMock . returnValues = returns ;
145+ break ;
146+ case SubstituteMethods . resolves :
147+ returnMock . returnValues = returns . map ( value => Promise . resolve ( value ) ) ;
148+ break ;
149+ case SubstituteMethods . rejects :
150+ returnMock . returnValues = returns . map ( value => Promise . reject ( value ) ) ;
151+ break ;
152+ }
153+ this . returns . push ( < ReturnMock > returnMock ) ;
143154 this . _calls . pop ( )
144155
145156 if ( this . callCount === 0 ) {
@@ -156,23 +167,6 @@ export class FunctionState implements ContextState {
156167 } ;
157168 }
158169
159- if ( property === SubstituteMethods . resolves ) {
160- return ( ...returns : any [ ] ) => {
161- if ( ! this . _lastArgs ) {
162- throw SubstituteException . generic ( 'Eh, there\'s a bug, no args recorded for this return :/' )
163- }
164- returns = returns . map ( value => Promise . resolve ( value ) )
165- this . returns . push ( {
166- returnValues : returns ,
167- returnIndex : 0 ,
168- args : this . _lastArgs
169- } )
170- this . _calls . pop ( )
171-
172- context . state = context . initialState ;
173- } ;
174- }
175-
176170 return context . proxy ;
177171 }
178172}
0 commit comments