Skip to content

Commit

Permalink
Merge pull request #377 from vatosarmat/master
Browse files Browse the repository at this point in the history
  • Loading branch information
jp928 committed Nov 2, 2021
2 parents dea9c86 + de90d6b commit 8cd347a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions __tests__/expectSaga/expectSaga.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
take,
takeEvery,
} from 'redux-saga/effects';
import { END } from 'redux-saga';
import { warn } from 'utils/logging';
import { delay } from 'utils/async';
import expectSaga from 'expectSaga';
Expand Down Expand Up @@ -304,3 +305,22 @@ test('terminates and does not wait for Call effect Promises', async () => {

expect(warn).not.toHaveBeenCalled();
});

test('terminates on END action', async () => {
warn.mockClear();

function* infiniteLoop() {
while (true) {
// Redux-saga docs:
// If you dispatch the END action, then all Sagas blocked on a take Effect
// will be terminated regardless of the specified pattern
yield take('HELLO_WORLD');
}
}

await expectSaga(infiniteLoop)
.dispatch(END)
.run();

expect(warn).not.toHaveBeenCalled();
});
3 changes: 2 additions & 1 deletion src/expectSaga/findDispatchableActionIndex.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
import { END } from 'redux-saga';
import { findIndex } from '../utils/array';

export default function findDispatchableActionIndex(
Expand Down Expand Up @@ -35,7 +36,7 @@ export default function findDispatchableActionIndex(
return -1;
}

return findIndex(actions, a => a.type === pattern);
return findIndex(actions, a => a.type === pattern || a.type === END.type);
}

function hasOwn(object: Object, key: string): boolean {
Expand Down

0 comments on commit 8cd347a

Please sign in to comment.