]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
test: refactor store test
authorEduardo San Martin Morote <posva13@gmail.com>
Sat, 23 Nov 2019 12:55:58 +0000 (13:55 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 25 Nov 2019 11:07:21 +0000 (12:07 +0100)
__tests__/createStore.spec.ts [deleted file]
__tests__/store.spec.ts [new file with mode: 0644]

diff --git a/__tests__/createStore.spec.ts b/__tests__/createStore.spec.ts
deleted file mode 100644 (file)
index 8a6c043..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-import { createStore } from '../src'
-
-describe('createStore', () => {
-  it('sets the initial state', () => {
-    const state = () => ({
-      a: true,
-      nested: {
-        a: { b: 'string' },
-      },
-    })
-
-    const store = createStore('main', state)
-    expect(store.state).toEqual({
-      a: true,
-      nested: {
-        a: { b: 'string' },
-      },
-    })
-  })
-})
diff --git a/__tests__/store.spec.ts b/__tests__/store.spec.ts
new file mode 100644 (file)
index 0000000..6e91a94
--- /dev/null
@@ -0,0 +1,52 @@
+import { createStore } from '../src'
+
+describe('Store', () => {
+  function buildStore() {
+    return createStore('main', () => ({
+      a: true as boolean,
+      nested: {
+        foo: 'foo',
+        a: { b: 'string' },
+      },
+    }))
+  }
+
+  it('sets the initial state', () => {
+    const store = buildStore()
+    expect(store.state).toEqual({
+      a: true,
+      nested: {
+        foo: 'foo',
+        a: { b: 'string' },
+      },
+    })
+  })
+
+  it('can replace its state', () => {
+    const store = buildStore()
+    store.replaceState({
+      a: false,
+      nested: {
+        foo: 'bar',
+        a: {
+          b: 'hey',
+        },
+      },
+    })
+    expect(store.state).toEqual({
+      a: false,
+      nested: {
+        foo: 'bar',
+        a: { b: 'hey' },
+      },
+    })
+  })
+
+  it('do not share the state between same id store', () => {
+    const store = buildStore()
+    const store2 = buildStore()
+    expect(store.state).not.toBe(store2.state)
+    store.state.nested.a.b = 'hey'
+    expect(store2.state.nested.a.b).toBe('string')
+  })
+})