From: Eduardo San Martin Morote Date: Sat, 23 Nov 2019 12:55:58 +0000 (+0100) Subject: test: refactor store test X-Git-Tag: v0.0.1~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43f827cfc9c5f59cfdff76261610e43e7eea9ffb;p=thirdparty%2Fvuejs%2Fpinia.git test: refactor store test --- diff --git a/__tests__/createStore.spec.ts b/__tests__/createStore.spec.ts deleted file mode 100644 index 8a6c0434..00000000 --- a/__tests__/createStore.spec.ts +++ /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 index 00000000..6e91a94b --- /dev/null +++ b/__tests__/store.spec.ts @@ -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') + }) +})