diff --git a/src/sagas/flash-firmware.test.ts b/src/sagas/flash-firmware.test.ts index 25ed6d58..cf63d4d6 100644 --- a/src/sagas/flash-firmware.test.ts +++ b/src/sagas/flash-firmware.test.ts @@ -35,8 +35,6 @@ import { } from '../actions/lwp3-bootloader'; import { didCompile } from '../actions/mpy'; import { HubType, Result } from '../protocols/lwp3-bootloader'; -import { EditorState } from '../reducers/editor'; -import { SettingsState } from '../reducers/settings'; import { createCountFunc } from '../utils/iter'; import flashFirmware from './flash-firmware'; @@ -69,7 +67,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc() }); - saga.setState({ settings: { flashCurrentProgram: false } as SettingsState }); + saga.setState({ settings: { flashCurrentProgram: false } }); // saga is triggered by this action @@ -199,9 +197,7 @@ describe('flashFirmware', () => { nextMessageId: createCountFunc(), }); - saga.setState({ - settings: { flashCurrentProgram: false } as SettingsState, - }); + saga.setState({ settings: { flashCurrentProgram: false } }); // saga is triggered by this action @@ -332,9 +328,7 @@ describe('flashFirmware', () => { nextMessageId: createCountFunc(), }); - saga.setState({ - settings: { flashCurrentProgram: false } as SettingsState, - }); + saga.setState({ settings: { flashCurrentProgram: false } }); // saga is triggered by this action @@ -387,8 +381,8 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc() }); saga.setState({ - editor: { current: editor } as EditorState, - settings: { flashCurrentProgram: true } as SettingsState, + editor: { current: editor }, + settings: { flashCurrentProgram: true }, }); // saga is triggered by this action diff --git a/src/sagas/license.test.ts b/src/sagas/license.test.ts index 609072f3..57d993cc 100644 --- a/src/sagas/license.test.ts +++ b/src/sagas/license.test.ts @@ -6,7 +6,7 @@ import { AsyncSaga, delay } from '../../test'; import { openLicenseDialog } from '../actions/app'; import { didFailToFetchList, didFetchList } from '../actions/license'; -import { LicenseList, LicenseState } from '../reducers/license'; +import { LicenseList } from '../reducers/license'; import license from './license'; afterAll(() => { @@ -24,7 +24,7 @@ describe('fetchLicenses', () => { // initially, license list starts as null, so fetch is called to get // the list - saga.setState({ license: { list: null } as LicenseState }); + saga.setState({ license: { list: null } }); saga.put(openLicenseDialog()); const action = await saga.take(); @@ -42,7 +42,7 @@ describe('fetchLicenses', () => { // after we have the list, we don't fetch it again since it will // always be the same list - saga.setState({ license: { list: testLicenseList } as LicenseState }); + saga.setState({ license: { list: testLicenseList } }); saga.put(openLicenseDialog()); // have to yield to be sure fetch call would have taken place on error @@ -56,7 +56,7 @@ describe('fetchLicenses', () => { jest.spyOn(globalThis, 'fetch').mockResolvedValue(failResponse); - saga.setState({ license: { list: null } as LicenseState }); + saga.setState({ license: { list: null } }); saga.put(openLicenseDialog()); const action = await saga.take(); diff --git a/src/sagas/settings.test.ts b/src/sagas/settings.test.ts index 6e0edb58..8e14d15b 100644 --- a/src/sagas/settings.test.ts +++ b/src/sagas/settings.test.ts @@ -6,7 +6,6 @@ import { AsyncSaga } from '../../test'; import { didStart } from '../actions/app'; import { didBooleanChange, didFailToSetBoolean, setBoolean } from '../actions/settings'; -import { SettingsState } from '../reducers/settings'; import { SettingId } from '../settings/user'; import settings from './settings'; @@ -221,7 +220,7 @@ describe('store settings to local storage', () => { throw testError; }); - saga.setState({ settings: { showDocs: false } as SettingsState }); + saga.setState({ settings: { showDocs: false } }); saga.put(setBoolean(SettingId.ShowDocs, true)); expect(mockSetItem).toHaveBeenCalled(); @@ -246,7 +245,7 @@ describe('store settings to local storage', () => { expect(value).toBe('true'); }); - saga.setState({ settings: { showDocs: false } as SettingsState }); + saga.setState({ settings: { showDocs: false } }); saga.put(setBoolean(SettingId.ShowDocs, true)); expect(mockSetItem).toHaveBeenCalled(); @@ -266,7 +265,7 @@ describe('store settings to local storage', () => { expect(value).toBe('false'); }); - saga.setState({ settings: { darkMode: true } as SettingsState }); + saga.setState({ settings: { darkMode: true } }); saga.put(setBoolean(SettingId.DarkMode, false)); expect(mockSetItem).toHaveBeenCalled(); @@ -286,7 +285,7 @@ describe('store settings to local storage', () => { expect(value).toBe('false'); }); - saga.setState({ settings: { flashCurrentProgram: true } as SettingsState }); + saga.setState({ settings: { flashCurrentProgram: true } }); saga.put(setBoolean(SettingId.FlashCurrentProgram, false)); expect(mockSetItem).toHaveBeenCalled(); diff --git a/test/index.ts b/test/index.ts index e5a7c588..b1833718 100644 --- a/test/index.ts +++ b/test/index.ts @@ -5,11 +5,15 @@ import { END, MulticastChannel, Saga, Task, runSaga, stdChannel } from 'redux-sa import { Action } from '../src/actions'; import { RootState } from '../src/reducers'; +type RecursivePartial = { + [P in keyof T]?: RecursivePartial; +}; + export class AsyncSaga { private channel: MulticastChannel; private dispatches: (Action | END)[]; private takers: { put: (action: Action | END) => void }[]; - private state: Partial; + private state: RecursivePartial; private task: Task; public constructor(saga: Saga, context?: Record) { @@ -63,7 +67,7 @@ export class AsyncSaga { return Promise.resolve(next); } - public setState(state: Partial): void { + public setState(state: RecursivePartial): void { this.state = state; }