Skip to content

Commit a06401e

Browse files
committed
Add redux tests
1 parent 5fbeb88 commit a06401e

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { testSaga } from "redux-saga-test-plan"
2+
import WorkspaceActions from "src/commons/workspace/WorkspaceActions"
3+
4+
import { combineSagaHandlers } from "../utils"
5+
6+
// Would have used spyOn, but for some reason that doesn't work properly
7+
jest.mock('src/commons/sagas/SafeEffects', () => ({
8+
...jest.requireActual('src/commons/sagas/SafeEffects'),
9+
// Mock wrap saga to just be a passthrough so that the identity
10+
// checking that testSaga uses will pass
11+
wrapSaga: (x: any) => x
12+
}))
13+
14+
test('test combineSagaHandlers', () => {
15+
const mockTakeEveryHandler = jest.fn()
16+
const mockTakeLatestHandler = jest.fn()
17+
const mockTakeLeadingHandler = jest.fn()
18+
19+
const saga = combineSagaHandlers({
20+
[WorkspaceActions.toggleUsingUpload.type]: mockTakeEveryHandler,
21+
[WorkspaceActions.toggleFolderMode.type]: {
22+
takeEvery: mockTakeEveryHandler
23+
},
24+
[WorkspaceActions.toggleUsingCse.type]: {
25+
takeLatest: mockTakeLatestHandler
26+
},
27+
[WorkspaceActions.toggleUsingSubst.type]: {
28+
takeLeading: mockTakeLeadingHandler
29+
}
30+
})
31+
32+
testSaga(saga)
33+
.next()
34+
.takeEvery(WorkspaceActions.toggleUsingUpload.type, mockTakeEveryHandler)
35+
.next()
36+
.takeEvery(WorkspaceActions.toggleFolderMode.type, mockTakeEveryHandler)
37+
.next()
38+
.takeLatest(WorkspaceActions.toggleUsingCse.type, mockTakeLatestHandler)
39+
.next()
40+
.takeLeading(WorkspaceActions.toggleUsingSubst.type, mockTakeLeadingHandler)
41+
.next()
42+
.isDone()
43+
})

src/commons/redux/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { type StrictEffect, takeEvery, takeLatest, takeLeading } from 'redux-sag
99

1010
import { safeTakeEvery, wrapSaga } from '../sagas/SafeEffects';
1111
import type { SourceActionType } from '../utils/ActionsHelper';
12-
import { ActionTypeToCreator, objectEntries } from '../utils/TypeHelper';
12+
import { type ActionTypeToCreator, objectEntries } from '../utils/TypeHelper';
1313

1414
/**
1515
* Creates actions, given a base name and base actions
@@ -54,7 +54,7 @@ type SagaHandlers = {
5454

5555
export function combineSagaHandlers(handlers: SagaHandlers) {
5656
return function* (): SagaIterator {
57-
for (const [actionName, saga] of objectEntries(handlers as SagaHandlers)) {
57+
for (const [actionName, saga] of objectEntries(handlers)) {
5858
if (saga === undefined) {
5959
continue;
6060
} else if (typeof saga === 'function') {

0 commit comments

Comments
 (0)