]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
test: fix lifespan test
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 6 Apr 2021 10:33:09 +0000 (12:33 +0200)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Thu, 8 Apr 2021 12:55:28 +0000 (14:55 +0200)
__tests__/lifespan.spec.ts

index 3eb55eb1b42a916533e889c2b5d5832655b0db39..af84547b85c0c47e4ef0b70b7e8b7c4a7199f1a5 100644 (file)
@@ -4,6 +4,7 @@ import VueCompositionAPI, {
   watch,
   nextTick,
   defineComponent,
+  onUnmounted,
 } from '@vue/composition-api'
 
 describe('Store Lifespan', () => {
@@ -36,7 +37,7 @@ describe('Store Lifespan', () => {
 
   // FIXME: https://github.com/vuejs/vue-test-utils/issues/1799
 
-  it.only('what', async () => {
+  it.skip('what', async () => {
     const localVue = createLocalVue()
     localVue.use(VueCompositionAPI)
     const n = 0
@@ -55,23 +56,27 @@ describe('Store Lifespan', () => {
 
     const inComponentWatch = jest.fn()
 
+    // FIXME: remove when the bug is fixed in VTU
+    let setupCalled = false
+
     const Component = defineComponent({
       render: (h) => h('p'),
       setup() {
-        const store = useStore()
-        watch(
-          () => store.n,
-          (n, oldN) => {
-            console.log('watching lolo', n, oldN)
-          }
-        )
-        watch(() => store.n, inComponentWatch)
-        console.log('increement', store.n)
-        store.n++
+        // console.log('setup called')
+        if (!setupCalled) {
+          const store = useStore()
+          watch(() => store.n, inComponentWatch)
+          store.n++
+          setupCalled = true
+
+          onUnmounted(() => {
+            setupCalled = false
+          })
+        }
       },
     })
 
-    let wrapper = mount(Component, { localVue })
+    let wrapper = mount(Component, { localVue, pinia })
 
     await nextTick()
     wrapper.destroy()
@@ -86,7 +91,7 @@ describe('Store Lifespan', () => {
     // FIXME: seems to be a bug in composition api
     // expect(inComponentWatch).toHaveBeenCalledTimes(1)
 
-    wrapper = mount(Component, { localVue })
+    wrapper = mount(Component, { localVue, pinia })
     await nextTick()
     wrapper.destroy()
     await nextTick()