Skip to content

Commit 7e8f175

Browse files
committed
wip(vitest-migration): runtime-core tests passing
1 parent e478755 commit 7e8f175

12 files changed

+41
-18
lines changed

packages/runtime-core/__tests__/apiOptions.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { vi } from 'vitest'
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
import { vi, type Mock } from 'vitest'
25
import {
36
h,
47
nodeOps,
@@ -187,9 +190,9 @@ describe('api: options', () => {
187190
const root = nodeOps.createElement('div')
188191
render(h(Comp), root)
189192

190-
function assertCall(spy: vi.Mock, callIndex: number, args: any[]) {
193+
function assertCall(spy: Mock, callIndex: number, args: any[]) {
191194
expect(spy.mock.calls[callIndex].slice(0, 2)).toMatchObject(args)
192-
expect(spy).toHaveReturnedWith(ctx)
195+
expect(spy.mock.results[callIndex].value).toBe(ctx)
193196
}
194197

195198
ctx.foo++
@@ -260,9 +263,9 @@ describe('api: options', () => {
260263
const root = nodeOps.createElement('div')
261264
render(h(Comp), root)
262265

263-
function assertCall(spy: vi.Mock, callIndex: number, args: any[]) {
266+
function assertCall(spy: Mock, callIndex: number, args: any[]) {
264267
expect(spy.mock.calls[callIndex].slice(0, 2)).toMatchObject(args)
265-
expect(spy).toHaveReturnedWith(ctx)
268+
expect(spy.mock.results[callIndex].value).toBe(ctx)
266269
}
267270

268271
ctx.foo++

packages/runtime-core/__tests__/apiSetupHelpers.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe('SFC <script setup> helpers', () => {
122122
})
123123
})
124124

125-
describe('createPropsRestProxy', () => {
125+
test('createPropsRestProxy', () => {
126126
const original = shallowReactive({
127127
foo: 1,
128128
bar: 2,

packages/runtime-core/__tests__/apiWatch.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ describe('api: watch', () => {
10201020
createApp(Comp).mount(root)
10211021

10221022
expect(instance).toBeDefined()
1023-
expect(source).toHaveBeenCalledWith(instance)
1023+
expect(source.mock.calls.some(args => args.includes(instance)))
10241024
})
10251025

10261026
test('should not leak `this.proxy` to setup()', () => {

packages/runtime-core/__tests__/componentProps.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
14
import { vi } from 'vitest'
25
import {
36
ComponentInternalInstance,

packages/runtime-core/__tests__/componentPublicInstance.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ describe('component: proxy', () => {
259259
expect(instanceProxy.isDisplayed).toBe(true)
260260
})
261261

262-
test('allow jest spying on proxy methods with Object.defineProperty', () => {
262+
test('allow test runner spying on proxy methods with Object.defineProperty', () => {
263263
// #5417
264264
let instanceProxy: any
265265
const Comp = {
@@ -305,16 +305,16 @@ describe('component: proxy', () => {
305305
instanceProxy.toggle()
306306
expect(getCalledTimes).toEqual(2)
307307

308-
// attaching jest spy, triggers the getter once, cache it and override the property.
308+
// attaching spy, triggers the getter once, and override the property.
309309
// also uses Object.defineProperty
310310
const spy = vi.spyOn(instanceProxy, 'toggle')
311311
expect(getCalledTimes).toEqual(3)
312312

313-
// expect getter to not evaluate the jest spy caches its value
313+
// vitest does not cache the spy like jest do
314314
const v3 = instanceProxy.toggle()
315315
expect(v3).toEqual('b')
316316
expect(spy).toHaveBeenCalled()
317-
expect(getCalledTimes).toEqual(3)
317+
expect(getCalledTimes).toEqual(4)
318318
})
319319

320320
test('defineProperty on proxy property with value descriptor', () => {

packages/runtime-core/__tests__/components/BaseTransition.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function assertCalls(
8787
}
8888

8989
function assertCalledWithEl(fn: any, expected: string, callIndex = 0) {
90-
expect(serialize((fn as vi.Mock).mock.calls[callIndex][0])).toBe(expected)
90+
expect(serialize(fn.mock.calls[callIndex][0])).toBe(expected)
9191
}
9292

9393
interface ToggleOptions {

packages/runtime-core/__tests__/components/Suspense.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
14
import { vi } from 'vitest'
25
import {
36
h,

packages/runtime-core/__tests__/components/Teleport.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
14
import { vi } from 'vitest'
25
import {
36
nodeOps,

packages/runtime-core/__tests__/helpers/withMemo.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
15
// since v-memo really is a compiler + runtime combo feature, we are performing
26
// more of an integration test here.
37
import { ComponentOptions, createApp, nextTick } from 'vue'

packages/runtime-core/__tests__/hydration.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
14
import { vi } from 'vitest'
25
import {
36
createSSRApp,
@@ -287,7 +290,7 @@ describe('SSR hydration', () => {
287290

288291
const teleportHtml = ctx.teleports!['#teleport2']
289292
expect(teleportHtml).toMatchInlineSnapshot(
290-
`"<span>foo</span><span class="foo"></span><!--teleport anchor--><span>foo2</span><span class="foo2"></span><!--teleport anchor-->"`
293+
'"<span>foo</span><span class=\\"foo\\"></span><!--teleport anchor--><span>foo2</span><span class=\\"foo2\\"></span><!--teleport anchor-->"'
291294
)
292295

293296
teleportContainer.innerHTML = teleportHtml
@@ -324,7 +327,7 @@ describe('SSR hydration', () => {
324327
msg.value = 'bar'
325328
await nextTick()
326329
expect(teleportContainer.innerHTML).toMatchInlineSnapshot(
327-
`"<span>bar</span><span class="bar"></span><!--teleport anchor--><span>bar2</span><span class="bar2"></span><!--teleport anchor-->"`
330+
'"<span>bar</span><span class=\\"bar\\"></span><!--teleport anchor--><span>bar2</span><span class=\\"bar2\\"></span><!--teleport anchor-->"'
328331
)
329332
})
330333

@@ -347,7 +350,7 @@ describe('SSR hydration', () => {
347350
const ctx: SSRContext = {}
348351
const mainHtml = await renderToString(h(Comp), ctx)
349352
expect(mainHtml).toMatchInlineSnapshot(
350-
`"<!--[--><div>foo</div><!--teleport start--><span>foo</span><span class="foo"></span><!--teleport end--><div class="foo2">bar</div><!--]-->"`
353+
'"<!--[--><div>foo</div><!--teleport start--><span>foo</span><span class=\\"foo\\"></span><!--teleport end--><div class=\\"foo2\\">bar</div><!--]-->"'
351354
)
352355

353356
const teleportHtml = ctx.teleports!['#teleport3']
@@ -386,7 +389,7 @@ describe('SSR hydration', () => {
386389
msg.value = 'bar'
387390
await nextTick()
388391
expect(container.innerHTML).toMatchInlineSnapshot(
389-
`"<!--[--><div>foo</div><!--teleport start--><span>bar</span><span class="bar"></span><!--teleport end--><div class="bar2">bar</div><!--]-->"`
392+
'"<!--[--><div>foo</div><!--teleport start--><span>bar</span><span class=\\"bar\\"></span><!--teleport end--><div class=\\"bar2\\">bar</div><!--]-->"'
390393
)
391394
})
392395

packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
14
// using DOM renderer because this case is mostly DOM-specific
25
import { vi } from 'vitest'
36
import {
@@ -15,7 +18,7 @@ import {
1518
Fragment,
1619
withModifiers
1720
} from '@vue/runtime-dom'
18-
import { PatchFlags } from '@vue/shared/src'
21+
import { PatchFlags } from '@vue/shared'
1922

2023
describe('attribute fallthrough', () => {
2124
it('should allow attrs to fallthrough', async () => {

packages/runtime-core/src/renderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ export const enum MoveType {
271271
}
272272

273273
export const queuePostRenderEffect = __FEATURE_SUSPENSE__
274-
? queueEffectWithSuspense
274+
? (fn: Function | Function[], suspense: SuspenseBoundary | null) =>
275+
queueEffectWithSuspense(fn, suspense)
275276
: queuePostFlushCb
276277

277278
/**

0 commit comments

Comments
 (0)