Skip to content

Commit

Permalink
chore: make mock assertion compatible with jest (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Feb 18, 2022
1 parent 65393f7 commit 7014c2b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 76 deletions.
4 changes: 2 additions & 2 deletions examples/mocks/package.json
Expand Up @@ -14,11 +14,11 @@
"dependencies": {
"@vueuse/integrations": "^7.6.2",
"axios": "^0.26.0",
"tinyspy": "^0.2.10"
"tinyspy": "^0.3.0"
},
"devDependencies": {
"@vitest/ui": "latest",
"vite": "latest",
"vitest": "latest"
}
}
}
4 changes: 2 additions & 2 deletions packages/vitest/package.json
Expand Up @@ -60,7 +60,7 @@
"chai": "^4.3.6",
"local-pkg": "^0.4.1",
"tinypool": "^0.1.2",
"tinyspy": "^0.2.10",
"tinyspy": "^0.3.0",
"vite": "^2.8.2"
},
"devDependencies": {
Expand Down Expand Up @@ -127,4 +127,4 @@
"engines": {
"node": ">=14.14.0"
}
}
}
4 changes: 2 additions & 2 deletions packages/vitest/src/integrations/jest-mock.ts
Expand Up @@ -103,8 +103,8 @@ export const spies = new Set<SpyInstance>()

export function isMockFunction(fn: any): fn is EnhancedSpy {
return typeof fn === 'function'
&& '__isSpy' in fn
&& fn.__isSpy
&& '_isMockFunction' in fn
&& fn._isMockFunction
}

export function spyOn<T, S extends Properties<Required<T>>>(
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/mocker.ts
Expand Up @@ -186,7 +186,7 @@ export class VitestMocker {
newObj[k] = this.mockObject(obj[k])
const type = getObjectType(obj[k])

if (type.includes('Function') && !obj[k].__isSpy) {
if (type.includes('Function') && !obj[k]._isMockFunction) {
this.spy.spyOn(newObj, k).mockImplementation(() => {})
Object.defineProperty(newObj[k], 'length', { value: 0 }) // tinyspy retains length, but jest doesnt
}
Expand Down
109 changes: 40 additions & 69 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7014c2b

Please sign in to comment.