Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function* root() {
const task = yield throttle(100, 'ACTION', worker, 'a1', 'a2')
yield take('CANCEL_WATCHER')
yield cancel(task)
}
function* worker(arg1, arg2, { payload }) {
actual.push([arg1, arg2, payload])
}
const dispatchedActions = []
for (let i = 0; i < 35; i++) {
dispatchedActions.push(
delayP(i * 10)
.then(() => store.dispatch({ type: 'ACTION', payload: i }))
.then(() => jest.advanceTimersByTime(10)), // next tick
)
}
Promise.resolve()
.then(() => jest.advanceTimersByTime(1)) // just start for the smallest tick
.then(() => jest.advanceTimersByTime(10)) // tick past first delay
return (
dispatchedActions[34] // wait so trailing dispatch gets processed
.then(() => jest.advanceTimersByTime(100))
.then(() => store.dispatch({ type: 'CANCEL_WATCHER' }))
// shouldn't be processed cause of getting canceled
.then(() => store.dispatch({ type: 'ACTION', payload: 40 }))
.then(() => {
test('delay', async () => {
const actual = []
const myVal = 'myValue'
const expected = [true, myVal]
const middleware = sagaMiddleware()
createStore(() => ({}), {}, applyMiddleware(middleware))
middleware.run(saga)
function* saga() {
actual.push(yield delay(1))
actual.push(yield delay(1, myVal))
}
await delayP(100)
expect(actual).toEqual(expected)
})
.then(() => delayP(2 * delayMs))
.then(() => {
export function* autoDismissal(id, timeout = 7000) {
yield delay(timeout);
yield call(dismissNotification, id);
}