@@ -13,6 +13,7 @@ let reset = (state: SpyInternalState) => {
13
13
state . callCount = 0
14
14
state . calls = [ ]
15
15
state . results = [ ]
16
+ state . next = [ ]
16
17
}
17
18
let defineState = ( spy : SpyInternal ) => {
18
19
define ( spy , S , { value : { reset : ( ) => reset ( spy [ S ] ) } } )
@@ -43,7 +44,7 @@ interface SpyInternalState<A extends any[] = any[], R = any> {
43
44
results : ResultFn < R > [ ]
44
45
reset ( ) : void
45
46
impl : ( ( ...args : A ) => R ) | undefined
46
- next : ResultFn < R > | null
47
+ next : ResultFn < R > [ ]
47
48
}
48
49
49
50
interface SpyInternalImplState < A extends any [ ] = any [ ] , R = any >
@@ -80,10 +81,10 @@ export function createInternalSpy<A extends any[], R>(
80
81
state . called = true
81
82
state . callCount ++
82
83
state . calls . push ( args )
83
- if ( state . next ) {
84
- let [ type , result ] = state . next
85
- state . results . push ( state . next )
86
- state . next = null
84
+ const next = state . next . shift ( )
85
+ if ( next ) {
86
+ state . results . push ( next )
87
+ const [ type , result ] = next
87
88
if ( type === 'ok' ) {
88
89
return result
89
90
}
@@ -150,11 +151,11 @@ export function populateSpy<A extends any[], R>(spy: SpyInternal<A, R>) {
150
151
define ( spy , n , { get : ( ) => I [ n ] , set : ( v ) => ( I [ n ] = v as never ) } )
151
152
)
152
153
defineValue ( spy , 'nextError' , ( error : any ) => {
153
- I . next = [ 'error' , error ]
154
+ I . next . push ( [ 'error' , error ] )
154
155
return I
155
156
} )
156
157
defineValue ( spy , 'nextResult' , ( result : R ) => {
157
- I . next = [ 'ok' , result ]
158
+ I . next . push ( [ 'ok' , result ] )
158
159
return I
159
160
} )
160
161
}
0 commit comments