]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
test: activate unwrapping tests
authorEduardo San Martin Morote <posva13@gmail.com>
Sat, 15 May 2021 13:25:22 +0000 (15:25 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Sat, 15 May 2021 13:25:22 +0000 (15:25 +0200)
__tests__/getters.spec.ts
__tests__/lifespan.spec.ts
__tests__/state.spec.ts

index 0a46c3450f1d2d3a19dad97bdd3a63f8bf965236..43d13fb94ee9691ced210422263982d31d10bbb2 100644 (file)
@@ -19,20 +19,18 @@ describe('Getters', () => {
         upperCaseName(): string {
           return this.name.toUpperCase()
         },
-        // works for js users but cannot be typed at the same time as `this`
-        // so it will have to be explicitly typed by the user
-        // https://github.com/posva/pinia/issues/249
-        callCheck(state: any) {
+        callCheck(state) {
           setImmediate(() => {
             // avoid getting tracked
+            // toRaw(state).callCount++
             state.callCount++
           })
           return state.forCallCheck
         },
-        doubleName() {
+        doubleName(): string {
           return this.upperCaseName
         },
-        composed() {
+        composed(): string {
           return this.upperCaseName + ': ok'
         },
         // TODO: I can't figure out how to pass `this` as an argument. Not sure
index 44d308e0382e5e6f3850294d3084b070ed5d1a7a..3180c0a79a9177c7999184ae4debc443daed1159 100644 (file)
@@ -38,27 +38,13 @@ describe('Store Lifespan', () => {
   const pinia = createPinia()
   localVue.use(PiniaPlugin)
 
-  // FIXME: https://github.com/vuejs/vue-test-utils/issues/1799
-
-  it.skip('what', async () => {
-    const localVue = createLocalVue()
-    const n = 0
-    const Component = defineComponent({
-      render: (h) => h('p'),
-      setup() {
-        // console.log('setup', n++)
-      },
-    })
-
-    mount(Component, { localVue })
-  })
-
   it('state reactivity outlives component life', async () => {
     const useStore = defineMyStore()
 
     const inComponentWatch = jest.fn()
 
     // FIXME: remove when the bug is fixed in VTU
+    // https://github.com/vuejs/vue-test-utils/issues/1799
     let setupCalled = false
 
     const Component = defineComponent({
@@ -90,8 +76,7 @@ describe('Store Lifespan', () => {
 
     store.n++
     await nextTick()
-    // FIXME: seems to be a bug in composition api
-    // expect(inComponentWatch).toHaveBeenCalledTimes(1)
+    expect(inComponentWatch).toHaveBeenCalledTimes(1)
 
     wrapper = mount(Component, { localVue, pinia })
     await nextTick()
@@ -107,8 +92,7 @@ describe('Store Lifespan', () => {
     expect(inComponentWatch).toHaveBeenCalledTimes(2)
   })
 
-  // FIXME: same limitation as above
-  it.skip('ref in state reactivity outlives component life', async () => {
+  it('ref in state reactivity outlives component life', async () => {
     let n: Ref<number>
     const globalWatch = jest.fn()
     const destroy = watch(() => pinia.state.value.a?.n, globalWatch)
index 83f5b95a61c22c119165162311a078248979e4f8..fafa0554dd990864240da34f4a80f35b306e5c3e 100644 (file)
@@ -1,4 +1,4 @@
-import { computed, nextTick, ref, watch } from '@vue/composition-api'
+import { computed, nextTick, reactive, ref, watch } from '@vue/composition-api'
 import { defineStore, setActivePinia, createPinia, Pinia } from '../src'
 
 describe('State', () => {
@@ -52,8 +52,29 @@ describe('State', () => {
     expect(spy).toHaveBeenCalledTimes(1)
   })
 
-  // FIXME: check why unwrapping is different with composition api
-  it.skip('unwraps refs', () => {
+  it('unwraps', () => {
+    const name = ref('Eduardo')
+    const counter = ref(0)
+    const double = computed({
+      get: () => counter.value * 2,
+      set(val) {
+        counter.value = val / 2
+      },
+    })
+
+    const store = reactive({ name, counter, double })
+    expect(store.name).toBe('Eduardo')
+    name.value = 'Ed'
+    expect(store.name).toBe('Ed')
+    store.name = 'Edu'
+    expect(store.name).toBe('Edu')
+
+    double.value = 4
+    expect(store.counter).toBe(2)
+    expect(counter.value).toBe(2)
+  })
+
+  it('unwraps refs', () => {
     const name = ref('Eduardo')
     const counter = ref(0)
     const double = computed({