Skip to content

Commit

Permalink
Fix conditional logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mjac0bs committed Oct 11, 2024
1 parent db4f8c3 commit e97c2c5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/manager/src/mocks/mockState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ export const emptyStore: MockState = {
export const createInitialMockStore = async (): Promise<MockState> => {
const mockState = await mswDB.getStore('mockState');

// If the keys in the mockState and emptyStore don't match, discard the current mockState because we've introduced new store values.
if (mockState && Object.keys(mockState) === Object.keys(emptyStore)) {
return mockState;
if (mockState) {
const mockStateKeys = Object.keys(mockState);
const emptyStoreKeys = Object.keys(emptyStore);

// Return the existing mockState if it includes all keys from the empty store;
// else, discard the existing mockState because we've introduced new values.
if (emptyStoreKeys.every((key) => mockStateKeys.includes(key))) {
return mockState;
}
}

return emptyStore;
Expand Down

0 comments on commit e97c2c5

Please sign in to comment.