test: drop state from AsyncSaga constructor params

This uses the real rootReducer to populate the initial state in the test
AsyncSaga. This way we don't have to populate default values. Since it
isn't used often, we can omit the parameter and just call the updateState()
method after creating the object if modifications are needed.
This commit is contained in:
David Lechner
2022-03-11 16:04:09 -06:00
parent 7b08d8a7bf
commit 31fb3b9e4c
9 changed files with 114 additions and 267 deletions
+10 -10
View File
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020-2021 The Pybricks Authors
// Copyright (c) 2020-2022 The Pybricks Authors
//
// Tests for settings sagas.
@@ -218,9 +218,7 @@ describe('startup', () => {
describe('store settings to local storage', () => {
test('failed storage', async () => {
const saga = new AsyncSaga(settings, {
settings: { showDocs: false, hubName: '' },
});
const saga = new AsyncSaga(settings);
const testError = new Error('local storage is disabled');
@@ -260,7 +258,7 @@ describe('store settings to local storage', () => {
});
test('showDocs', async () => {
const saga = new AsyncSaga(settings, { settings: { showDocs: false } });
const saga = new AsyncSaga(settings);
const mockSetItem = jest
.spyOn(Object.getPrototypeOf(window.localStorage), 'setItem')
@@ -279,7 +277,9 @@ describe('store settings to local storage', () => {
});
test('darkMode', async () => {
const saga = new AsyncSaga(settings, { settings: { darkMode: true } });
const saga = new AsyncSaga(settings);
saga.updateState({ settings: { darkMode: true } });
const mockSetItem = jest
.spyOn(Object.getPrototypeOf(window.localStorage), 'setItem')
@@ -298,9 +298,9 @@ describe('store settings to local storage', () => {
});
test('flashCurrentProgram', async () => {
const saga = new AsyncSaga(settings, {
settings: { flashCurrentProgram: true },
});
const saga = new AsyncSaga(settings);
saga.updateState({ settings: { flashCurrentProgram: true } });
const mockSetItem = jest
.spyOn(Object.getPrototypeOf(window.localStorage), 'setItem')
@@ -375,7 +375,7 @@ describe('storage monitor', () => {
describe('toggle', () => {
test('showDocs', async () => {
const saga = new AsyncSaga(settings, { settings: { showDocs: false } });
const saga = new AsyncSaga(settings);
const mockSetItem = jest
.spyOn(Object.getPrototypeOf(window.localStorage), 'setItem')