Skip to content

Commit

Permalink
fix: revert reusing spy when calling spyOn
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Sep 9, 2024
1 parent 88cf76b commit 9a54c10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions src/spyOn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,24 @@ export function internalSpyOn<T, K extends string & keyof T>(

if (!mock) mock = origin

let fn: SpyInternal
if (origin && S in origin) {
fn = origin as SpyInternal
} else {
fn = createInternalSpy(mock)
if (accessType === 'value') {
prototype(fn, origin)
}

const state = fn[S]
defineValue(state, 'restore', restore)
defineValue(state, 'getOriginal', () => (ssr ? origin() : origin))
defineValue(state, 'willCall', (newCb: Procedure) => {
state.impl = newCb
return fn
})
// let fn: SpyInternal
// if (origin && S in origin) {
// fn = origin as SpyInternal
// } else {
let fn = createInternalSpy(mock)
if (accessType === 'value') {
prototype(fn, origin)
}

const state = fn[S]
defineValue(state, 'restore', restore)
defineValue(state, 'getOriginal', () => (ssr ? origin() : origin))
defineValue(state, 'willCall', (newCb: Procedure) => {
state.impl = newCb
return fn
})
// }

reassign(
ssr
? () => {
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ test('next in a row', () => {
expect(cb()).toBe(undefined)
})

test('spying twice and unspying restores original method', () => {
test.todo('spying twice and unspying restores original method', () => {
const obj = {
method: () => 1,
}
Expand Down

0 comments on commit 9a54c10

Please sign in to comment.