Repository URL to install this package:
|
Version:
3.7.1 ▾
|
import { delay } from 'redux-saga';
import { put, spawn, race, take, call } from 'redux-saga/effects';
import { waitForChooseExperiment, waitForOptimize } from './sagaHelpers';
describe('sagaHelpers', () => {
describe('waitForOptimize', () => {
it('should return the right order of yields', () => {
const abTest = 'Test';
const inputSaga = function*() {
yield put({
type: 'test',
});
};
const internalType = `@doodle/ab/internal/DEPEND_ON_${abTest}`;
const saga = waitForOptimize(abTest)(inputSaga);
const firstYieldExpected = spawn(waitForChooseExperiment, { type: internalType }, abTest);
const secondYieldExpected = race({ action: take(internalType), timeout: delay(1000) });
const thirdYieldExpected = call(inputSaga);
expect(saga.next().value).toEqual(firstYieldExpected);
const secondYield = saga.next().value;
expect(secondYield['@@redux-saga/IO']).toEqual(secondYieldExpected['@@redux-saga/IO']);
expect(secondYield.RACE.action).toEqual(secondYieldExpected.RACE.action);
expect(secondYield.RACE.timeout['@@redux-saga/CANCEL_PROMISE']).toBeDefined();
expect(typeof secondYield.RACE.timeout['@@redux-saga/CANCEL_PROMISE']).toBe('function');
expect(saga.next().value).toEqual(thirdYieldExpected);
});
});
});