From: Eduardo San Martin Morote Date: Thu, 31 Mar 2022 16:08:03 +0000 (+0200) Subject: test: add skipped test for #1129 [skip ci] X-Git-Tag: @pinia/testing@0.0.11~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9b7a472b790c8dabb7fd6056cd4ff43e92873232;p=thirdparty%2Fvuejs%2Fpinia.git test: add skipped test for #1129 [skip ci] --- diff --git a/packages/pinia/__tests__/subscriptions.spec.ts b/packages/pinia/__tests__/subscriptions.spec.ts index cacd8c29..6846f1ca 100644 --- a/packages/pinia/__tests__/subscriptions.spec.ts +++ b/packages/pinia/__tests__/subscriptions.spec.ts @@ -2,6 +2,8 @@ import { createPinia, defineStore, MutationType, setActivePinia } from '../src' import { mount } from '@vue/test-utils' import { nextTick } from 'vue' +const delay = (t: number) => new Promise((r) => setTimeout(r, t)) + describe('Subscriptions', () => { const useStore = defineStore({ id: 'main', @@ -200,6 +202,38 @@ describe('Subscriptions', () => { expect(spy2).toHaveBeenCalledTimes(1) }) + it.skip('triggers pre subscriptions only once on $patch', async () => { + const s1 = useStore() + const spy1 = jest.fn() + + s1.$subscribe(spy1, { flush: 'pre' }) + + // First mutation: works as expected + s1.$patch({ user: 'Edu' }) + // anything else than awaiting a non promise or Promise.resolve() works + await false + // await Promise.resolve(false) + // adding an extra await works + // await false + // adding any other delay also works + // await delay(20) + // await nextTick() + expect(spy1).toHaveBeenCalledTimes(1) + expect(spy1).not.toHaveBeenCalledWith( + expect.objectContaining({ type: MutationType.direct }), + s1.$state + ) + + s1.$patch({ user: 'Myk' }) + await nextTick() + + expect(spy1).toHaveBeenCalledTimes(2) + expect(spy1).not.toHaveBeenCalledWith( + expect.objectContaining({ type: MutationType.direct }), + s1.$state + ) + }) + it('removes on unmount', async () => { const pinia = createPinia() setActivePinia(pinia)