Skip to content

Commit 9a54c10

Browse files
committed
fix: revert reusing spy when calling spyOn
1 parent 88cf76b commit 9a54c10

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

Diff for: src/spyOn.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,24 @@ export function internalSpyOn<T, K extends string & keyof T>(
116116

117117
if (!mock) mock = origin
118118

119-
let fn: SpyInternal
120-
if (origin && S in origin) {
121-
fn = origin as SpyInternal
122-
} else {
123-
fn = createInternalSpy(mock)
124-
if (accessType === 'value') {
125-
prototype(fn, origin)
126-
}
127-
128-
const state = fn[S]
129-
defineValue(state, 'restore', restore)
130-
defineValue(state, 'getOriginal', () => (ssr ? origin() : origin))
131-
defineValue(state, 'willCall', (newCb: Procedure) => {
132-
state.impl = newCb
133-
return fn
134-
})
119+
// let fn: SpyInternal
120+
// if (origin && S in origin) {
121+
// fn = origin as SpyInternal
122+
// } else {
123+
let fn = createInternalSpy(mock)
124+
if (accessType === 'value') {
125+
prototype(fn, origin)
135126
}
136127

128+
const state = fn[S]
129+
defineValue(state, 'restore', restore)
130+
defineValue(state, 'getOriginal', () => (ssr ? origin() : origin))
131+
defineValue(state, 'willCall', (newCb: Procedure) => {
132+
state.impl = newCb
133+
return fn
134+
})
135+
// }
136+
137137
reassign(
138138
ssr
139139
? () => {

Diff for: test/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ test('next in a row', () => {
756756
expect(cb()).toBe(undefined)
757757
})
758758

759-
test('spying twice and unspying restores original method', () => {
759+
test.todo('spying twice and unspying restores original method', () => {
760760
const obj = {
761761
method: () => 1,
762762
}

0 commit comments

Comments
 (0)