From: Eduardo San Martin Morote Date: Sat, 15 May 2021 13:25:22 +0000 (+0200) Subject: test: activate unwrapping tests X-Git-Tag: v0.5.0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2e9b945db8c0c7b0ce30de556eb07b679e5376c;p=thirdparty%2Fvuejs%2Fpinia.git test: activate unwrapping tests --- diff --git a/__tests__/getters.spec.ts b/__tests__/getters.spec.ts index 0a46c345..43d13fb9 100644 --- a/__tests__/getters.spec.ts +++ b/__tests__/getters.spec.ts @@ -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 diff --git a/__tests__/lifespan.spec.ts b/__tests__/lifespan.spec.ts index 44d308e0..3180c0a7 100644 --- a/__tests__/lifespan.spec.ts +++ b/__tests__/lifespan.spec.ts @@ -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 const globalWatch = jest.fn() const destroy = watch(() => pinia.state.value.a?.n, globalWatch) diff --git a/__tests__/state.spec.ts b/__tests__/state.spec.ts index 83f5b95a..fafa0554 100644 --- a/__tests__/state.spec.ts +++ b/__tests__/state.spec.ts @@ -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({