]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip(vitest-migration): runtime-core tests passing
authorEvan You <yyx990803@gmail.com>
Thu, 26 Jan 2023 12:46:46 +0000 (20:46 +0800)
committerEvan You <yyx990803@gmail.com>
Thu, 26 Jan 2023 12:48:47 +0000 (20:48 +0800)
12 files changed:
packages/runtime-core/__tests__/apiOptions.spec.ts
packages/runtime-core/__tests__/apiSetupHelpers.spec.ts
packages/runtime-core/__tests__/apiWatch.spec.ts
packages/runtime-core/__tests__/componentProps.spec.ts
packages/runtime-core/__tests__/componentPublicInstance.spec.ts
packages/runtime-core/__tests__/components/BaseTransition.spec.ts
packages/runtime-core/__tests__/components/Suspense.spec.ts
packages/runtime-core/__tests__/components/Teleport.spec.ts
packages/runtime-core/__tests__/helpers/withMemo.spec.ts
packages/runtime-core/__tests__/hydration.spec.ts
packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts
packages/runtime-core/src/renderer.ts

index 14c7f3852d750399bcef2e5691912f2e04488d03..c143a9dcc5e729e0c69e3d91c97eb5f8acccd24d 100644 (file)
@@ -1,4 +1,7 @@
-import { vi } from 'vitest'
+/**
+ * @vitest-environment jsdom
+ */
+import { vi, type Mock } from 'vitest'
 import {
   h,
   nodeOps,
@@ -187,9 +190,9 @@ describe('api: options', () => {
     const root = nodeOps.createElement('div')
     render(h(Comp), root)
 
-    function assertCall(spy: vi.Mock, callIndex: number, args: any[]) {
+    function assertCall(spy: Mock, callIndex: number, args: any[]) {
       expect(spy.mock.calls[callIndex].slice(0, 2)).toMatchObject(args)
-      expect(spy).toHaveReturnedWith(ctx)
+      expect(spy.mock.results[callIndex].value).toBe(ctx)
     }
 
     ctx.foo++
@@ -260,9 +263,9 @@ describe('api: options', () => {
     const root = nodeOps.createElement('div')
     render(h(Comp), root)
 
-    function assertCall(spy: vi.Mock, callIndex: number, args: any[]) {
+    function assertCall(spy: Mock, callIndex: number, args: any[]) {
       expect(spy.mock.calls[callIndex].slice(0, 2)).toMatchObject(args)
-      expect(spy).toHaveReturnedWith(ctx)
+      expect(spy.mock.results[callIndex].value).toBe(ctx)
     }
 
     ctx.foo++
index ca0759cade3328459931da24532390b45827e19e..aa4e04e80f4f3979753df69a1a52d10acb174d02 100644 (file)
@@ -122,7 +122,7 @@ describe('SFC <script setup> helpers', () => {
     })
   })
 
-  describe('createPropsRestProxy', () => {
+  test('createPropsRestProxy', () => {
     const original = shallowReactive({
       foo: 1,
       bar: 2,
index 45ced8947e2f19b426057b3b0b7463668cf7f065..b9670820cd964f76ae8f79caa0047aa1ef510a81 100644 (file)
@@ -1020,7 +1020,7 @@ describe('api: watch', () => {
     createApp(Comp).mount(root)
 
     expect(instance).toBeDefined()
-    expect(source).toHaveBeenCalledWith(instance)
+    expect(source.mock.calls.some(args => args.includes(instance)))
   })
 
   test('should not leak `this.proxy` to setup()', () => {
index 64da57e0d52d1cae4a4a482e78ee50b57b45f78c..df46da6807a708f4dedbc40be7c6acd456b7e162 100644 (file)
@@ -1,3 +1,6 @@
+/**
+ * @vitest-environment jsdom
+ */
 import { vi } from 'vitest'
 import {
   ComponentInternalInstance,
index f1379e65ca522792e4c44eab0215c2a05063b9b4..47605bfe2cc8c865ea99f5e367aa89b3f5452c47 100644 (file)
@@ -259,7 +259,7 @@ describe('component: proxy', () => {
     expect(instanceProxy.isDisplayed).toBe(true)
   })
 
-  test('allow jest spying on proxy methods with Object.defineProperty', () => {
+  test('allow test runner spying on proxy methods with Object.defineProperty', () => {
     // #5417
     let instanceProxy: any
     const Comp = {
@@ -305,16 +305,16 @@ describe('component: proxy', () => {
     instanceProxy.toggle()
     expect(getCalledTimes).toEqual(2)
 
-    // attaching jest spy, triggers the getter once, cache it and override the property.
+    // attaching spy, triggers the getter once, and override the property.
     // also uses Object.defineProperty
     const spy = vi.spyOn(instanceProxy, 'toggle')
     expect(getCalledTimes).toEqual(3)
 
-    // expect getter to not evaluate the jest spy caches its value
+    // vitest does not cache the spy like jest do
     const v3 = instanceProxy.toggle()
     expect(v3).toEqual('b')
     expect(spy).toHaveBeenCalled()
-    expect(getCalledTimes).toEqual(3)
+    expect(getCalledTimes).toEqual(4)
   })
 
   test('defineProperty on proxy property with value descriptor', () => {
index b68562adb087336dc6588cc0921f4c27b15e449f..2622cf64bfe0312ef81b502e7448a1aecda925d6 100644 (file)
@@ -87,7 +87,7 @@ function assertCalls(
 }
 
 function assertCalledWithEl(fn: any, expected: string, callIndex = 0) {
-  expect(serialize((fn as vi.Mock).mock.calls[callIndex][0])).toBe(expected)
+  expect(serialize(fn.mock.calls[callIndex][0])).toBe(expected)
 }
 
 interface ToggleOptions {
index f71d6bf1efe76d297301cbe9b588cc7cd8725643..b748f52011f3e6e20956df084bed84346a3f1089 100644 (file)
@@ -1,3 +1,6 @@
+/**
+ * @vitest-environment jsdom
+ */
 import { vi } from 'vitest'
 import {
   h,
index b9ae3a8a42dba674aa76ae4fc6d356e449a941c4..95fbf781671be1dc3c8e0ad4cd6811717e836891 100644 (file)
@@ -1,3 +1,6 @@
+/**
+ * @vitest-environment jsdom
+ */
 import { vi } from 'vitest'
 import {
   nodeOps,
index 9b7fcfc017f4a1dcc4218550d963941557f68db6..60b5132bd5eadb8ca0f25f522af679fef63a648a 100644 (file)
@@ -1,3 +1,7 @@
+/**
+ * @vitest-environment jsdom
+ */
+
 // since v-memo really is a compiler + runtime combo feature, we are performing
 // more of an integration test here.
 import { ComponentOptions, createApp, nextTick } from 'vue'
index 555ccf90d198787f9d96686109980136b17c6821..fece1a33f9dfac9ac3f5abb3f980c8db6a7a99fd 100644 (file)
@@ -1,3 +1,6 @@
+/**
+ * @vitest-environment jsdom
+ */
 import { vi } from 'vitest'
 import {
   createSSRApp,
@@ -287,7 +290,7 @@ describe('SSR hydration', () => {
 
     const teleportHtml = ctx.teleports!['#teleport2']
     expect(teleportHtml).toMatchInlineSnapshot(
-      `"<span>foo</span><span class="foo"></span><!--teleport anchor--><span>foo2</span><span class="foo2"></span><!--teleport anchor-->"`
+      '"<span>foo</span><span class=\\"foo\\"></span><!--teleport anchor--><span>foo2</span><span class=\\"foo2\\"></span><!--teleport anchor-->"'
     )
 
     teleportContainer.innerHTML = teleportHtml
@@ -324,7 +327,7 @@ describe('SSR hydration', () => {
     msg.value = 'bar'
     await nextTick()
     expect(teleportContainer.innerHTML).toMatchInlineSnapshot(
-      `"<span>bar</span><span class="bar"></span><!--teleport anchor--><span>bar2</span><span class="bar2"></span><!--teleport anchor-->"`
+      '"<span>bar</span><span class=\\"bar\\"></span><!--teleport anchor--><span>bar2</span><span class=\\"bar2\\"></span><!--teleport anchor-->"'
     )
   })
 
@@ -347,7 +350,7 @@ describe('SSR hydration', () => {
     const ctx: SSRContext = {}
     const mainHtml = await renderToString(h(Comp), ctx)
     expect(mainHtml).toMatchInlineSnapshot(
-      `"<!--[--><div>foo</div><!--teleport start--><span>foo</span><span class="foo"></span><!--teleport end--><div class="foo2">bar</div><!--]-->"`
+      '"<!--[--><div>foo</div><!--teleport start--><span>foo</span><span class=\\"foo\\"></span><!--teleport end--><div class=\\"foo2\\">bar</div><!--]-->"'
     )
 
     const teleportHtml = ctx.teleports!['#teleport3']
@@ -386,7 +389,7 @@ describe('SSR hydration', () => {
     msg.value = 'bar'
     await nextTick()
     expect(container.innerHTML).toMatchInlineSnapshot(
-      `"<!--[--><div>foo</div><!--teleport start--><span>bar</span><span class="bar"></span><!--teleport end--><div class="bar2">bar</div><!--]-->"`
+      '"<!--[--><div>foo</div><!--teleport start--><span>bar</span><span class=\\"bar\\"></span><!--teleport end--><div class=\\"bar2\\">bar</div><!--]-->"'
     )
   })
 
index 6dd51b368dbc0672fb85dc6f4d451f36ecab6839..197e3f3acd1106ebc7d0f7b0d87e325253f35624 100644 (file)
@@ -1,3 +1,6 @@
+/**
+ * @vitest-environment jsdom
+ */
 // using DOM renderer because this case is mostly DOM-specific
 import { vi } from 'vitest'
 import {
@@ -15,7 +18,7 @@ import {
   Fragment,
   withModifiers
 } from '@vue/runtime-dom'
-import { PatchFlags } from '@vue/shared/src'
+import { PatchFlags } from '@vue/shared'
 
 describe('attribute fallthrough', () => {
   it('should allow attrs to fallthrough', async () => {
index 4dfbc65699697ef7c4134f452c2dfb795d958396..3a4608681f965c8b60337933496f03cef4f4439c 100644 (file)
@@ -271,7 +271,8 @@ export const enum MoveType {
 }
 
 export const queuePostRenderEffect = __FEATURE_SUSPENSE__
-  ? queueEffectWithSuspense
+  ? (fn: Function | Function[], suspense: SuspenseBoundary | null) =>
+      queueEffectWithSuspense(fn, suspense)
   : queuePostFlushCb
 
 /**