From e5baabd6ed84331b7337bb15d4eba5820059a0b6 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 19 Jul 2021 16:53:53 +0200 Subject: [PATCH] test: $patch arrays --- __tests__/store.patch.spec.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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) => { -- 2.47.2