瀏覽代碼

test: unit/features/component passing

Evan You 3 年之前
父節點
當前提交
250bc17d51

+ 22 - 0
test/helpers/to-have-warned.ts

@@ -62,15 +62,37 @@ expect.extend({
           `expected "${received}" to have been warned ${n} times but got ${found}.`
       }
     }
+  },
+
+  toHaveBeenTipped(received: string) {
+    const passed = tip.mock.calls.some((args) => args[0].includes(received))
+    if (passed) {
+      return {
+        pass: true,
+        message: () => `expected "${received}" not to have been tipped.`
+      }
+    } else {
+      const msgs = warn.mock.calls.map((args) => args[0]).join('\n - ')
+      return {
+        pass: false,
+        message: () =>
+          `expected "${received}" to have been tipped` +
+          (msgs.length
+            ? `.\n\nActual messages:\n\n - ${msgs}`
+            : ` but no tip was recorded.`)
+      }
+    }
   }
 })
 
 let warn: SpyInstance
+let tip: SpyInstance
 const asserted: Set<string> = new Set()
 
 beforeEach(() => {
   asserted.clear()
   warn = vi.spyOn(console, 'error')
+  tip = vi.spyOn(console, 'warn').mockImplementation(() => {})
   warn.mockImplementation(() => {})
 })
 

+ 1 - 0
test/test-env.d.ts

@@ -20,6 +20,7 @@ declare namespace jest {
     toHaveBeenWarned(): R
     toHaveBeenWarnedLast(): R
     toHaveBeenWarnedTimes(n: number): R
+    toHaveBeenTipped(): R
     toHaveClass(cls: string): R
   }
 }

+ 3 - 4
test/unit/features/component/component-scoped-slot.spec.ts

@@ -746,14 +746,14 @@ describe('Component scoped slot', () => {
       })
 
       it('should warn v-slot usage on non-component elements', () => {
-        const vm = new Vue({
+        new Vue({
           template: `<div ${syntax}="foo"/>`
         }).$mount()
         expect(`v-slot can only be used on components or <template>`).toHaveBeenWarned()
       })
 
       it('should warn mixed usage', () => {
-        const vm = new Vue({
+        new Vue({
           template: `<foo><bar slot="one" slot-scope="bar" ${syntax}="bar"></bar></foo>`,
           components: { Foo, Bar }
         }).$mount()
@@ -802,7 +802,7 @@ describe('Component scoped slot', () => {
     })
 
     it('should warn mixed root-default and named slots', () => {
-      const vm = new Vue({
+      new Vue({
         template: `
           <foo #default="foo">
             {{ foo }}
@@ -938,7 +938,6 @@ describe('Component scoped slot', () => {
   // #9432: async components inside a scoped slot should trigger update of the
   // component that invoked the scoped slot, not the lexical context component.
   it('async component inside scoped slot', done => {
-    let p
     const vm = new Vue({
       template: `
         <foo>

+ 2 - 1
test/vitest.setup.ts

@@ -1,4 +1,5 @@
-(global as any).__WEEX__ = false
+;(global as any).__WEEX__ = false
+process.env.NEW_SLOT_SYNTAX = 'true'
 
 import './helpers/shim-done'
 import './helpers/to-have-warned'