mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-21 17:18:52 +00:00
Add a few more generic assertions about serialized state
This commit is contained in:
parent
8f6ccbbe4e
commit
f3e07586ec
1 changed files with 12 additions and 0 deletions
|
|
@ -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()
|
||||
);
|
||||
|
|
@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue