]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
test: $patch arrays
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 19 Jul 2021 14:53:53 +0000 (16:53 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 19 Jul 2021 14:53:53 +0000 (16:53 +0200)
__tests__/store.patch.spec.ts

index f6c8037729b56384026c3021f6d74ec08b8b40a1..fbba9a75b079ade45cfd5308aba3aa3ff61d69e2 100644 (file)
@@ -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) => {