From f3e07586ec0040a0cdd1fa3cd24c4b68c72f50ad Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sun, 30 Sep 2018 09:16:34 -0700 Subject: [PATCH] Add a few more generic assertions about serialized state --- js/serialization.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/js/serialization.test.ts b/js/serialization.test.ts index 7a88f369..dacf87ef 100644 --- a/js/serialization.test.ts +++ b/js/serialization.test.ts @@ -42,10 +42,16 @@ function testSerialization({ }: SerializationTestParams) { test(name, () => { const firstStore = getStore(); + // Does not match the expected selection in the initial state + expect(selector(firstStore.getState())).not.toEqual(expected); + firstStore.dispatch(action); // Ensure we actually changed something expect(firstStore.getState()).not.toEqual(getStore().getState()); + // Ensure the expectation is true before we serialize + expect(selector(firstStore.getState())).toEqual(expected); + const serializedState = Selectors.getSerlializedState( firstStore.getState() ); @@ -57,14 +63,20 @@ function testSerialization({ const readSerializedState = readFixture(name); + // Ensure our serialization strategy hasn't changed since we last serialized expect(readSerializedState).toEqual(serializedState); + // Try to apply this serialized state to the default state const secondStore = getStore(); secondStore.dispatch({ type: LOAD_SERIALIZED_STATE, serializedState: readSerializedState }); + + // Ensure our restored state conforms to expectation expect(selector(secondStore.getState())).toEqual(expected); + + // TODO: Try to apply the serialized state to a complex non-initial state }); }