Skip to content

Commit

Permalink
Add a few more generic assertions about serialized state
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed Oct 1, 2018
1 parent 6ecc514 commit a826758
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions js/serialization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ function testSerialization<T>({
}: SerializationTestParams<T>) {
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()
);
Expand All @@ -57,14 +63,20 @@ function testSerialization<T>({

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
});
}

Expand Down

0 comments on commit a826758

Please sign in to comment.