From: Eduardo San Martin Morote Date: Mon, 19 Jul 2021 14:53:53 +0000 (+0200) Subject: test: $patch arrays X-Git-Tag: v2.0.0-rc.0~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5baabd6ed84331b7337bb15d4eba5820059a0b6;p=thirdparty%2Fvuejs%2Fpinia.git test: $patch arrays --- diff --git a/__tests__/store.patch.spec.ts b/__tests__/store.patch.spec.ts index f6c80377..fbba9a75 100644 --- a/__tests__/store.patch.spec.ts +++ b/__tests__/store.patch.spec.ts @@ -31,6 +31,30 @@ describe('store.$patch', () => { }) }) + it('replaces whole arrays', () => { + const store = useStore() + store.$patch({ list: [1, 2] }) + expect(store.$state.list).toEqual([1, 2]) + }) + + it('replaces whole nested arrays', () => { + const store = useStore() + // @ts-expect-error: new state + store.$patch({ nested: { list: [1, 2] } }) + expect(store.$state.nested).toEqual({ + foo: 'foo', + a: { b: 'string' }, + list: [1, 2], + }) + // @ts-expect-error: new state + store.$patch({ nested: { list: [] } }) + expect(store.$state.nested).toEqual({ + foo: 'foo', + a: { b: 'string' }, + list: [], + }) + }) + it('patches using a function', () => { const store = useStore() store.$patch((state) => {