How to use redux-saga-test-plan - 10 common examples

To help you get started, we’ve selected a few redux-saga-test-plan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github source-academy / cadet-frontend / src / sagas / __tests__ / workspaces.ts View on Github external
test('with error in the code, should return correct line number in error', () => {
      code = '// Prepend\n error';
      state = generateDefaultState(workspaceLocation, { editorPrepend: '// Prepend' });

      runInContext(code, context, { scheduler: 'preemptive', originalMaxExecTime: 1000 }).then(
        result => (context = (result as Finished).context)
      );

      const errors = context.errors.map((error: SourceError) => {
        const newError = cloneDeep(error);
        newError.location.start.line = newError.location.start.line - 1;
        newError.location.end.line = newError.location.end.line - 1;
        return newError;
      });

      return expectSaga(evalCode, code, context, execTime, workspaceLocation, actionType)
        .withState(state)
        .call(runInContext, code, context, {
          scheduler: 'preemptive',
          originalMaxExecTime: execTime
        })
        .put(actions.evalInterpreterError(errors, workspaceLocation))
        .silentRun();
    });
  });
github TimDaub / ERC721-wallet / __tests__ / sagas / fetchTransactions.js View on Github external
// @format
import { expectSaga } from "redux-saga-test-plan";
import { call } from "redux-saga/effects";
import Web3 from "web3";

import { fetchTransactionsBatch } from "../../src/sagas/fetchTransactions";

expectSaga.DEFAULT_TIMEOUT = 500;

describe("transaction fetching", () => {
  it("should process transactions correctly and return a token", async () => {
    const contractAddress = "0x9326f84fcca8a136da3a4f71bbffbde6635c58da";
    const address = "0x51Ff1fab76079d20418d1c74DA65653FfE3fD0aa";
    const web3Mock = {
      eth: {
        net: {
          getId: jest.fn(() => 1)
        },
        Contract: jest.fn(() => {
          return {
            getPastEvents: jest
              .fn()
              .mockReturnValueOnce([{ returnValues: { _tokenId: 1 } }]) //outputs
              .mockReturnValueOnce([{ returnValues: { _tokenId: 2 } }]), // inputs
github amiuhle / kasisto / src / sagas / __tests__ / payments.js View on Github external
// import { throwError } from 'redux-saga-test-plan/providers'

import {
  processPayment
} from '../payments'

import {
  requestPayment,
  setAmount,
  setTip
} from '../../actions/payments'

import * as types from '../../actions/constants/payments'

// Travis CI timeout using default 250ms
expectSaga.DEFAULT_TIMEOUT = process.env.ASYNC_TIMEOUT || expectSaga.DEFAULT_TIMEOUT

const at = (timestamp, execute) => {
  const { Date } = global
  global.Date = jest.fn(() => new Date(timestamp))
  try {
    return execute()
  } finally {
    global.Date = Date
  }
}

const URL_BASE = 'https://stagenet.kasisto.io:28082'
const URL_PATH = '/json_rpc'
const URL = `${URL_BASE}${URL_PATH}`

const mockRequest = nock(URL_BASE)
github cockroachdb / cockroach-gen / pkg / ui / src / redux / metrics.spec.ts View on Github external
it("correctly accumulates batches", function () {
        const requestAction = metrics.requestMetrics(
          "id",
          createRequest(shortTimespan, "short.1"),
        );
        const beginAction = metrics.beginMetrics(
          requestAction.payload.id,
          requestAction.payload.data,
        );

        return (
          expectSaga(metrics.queryMetricsSaga)
            // Stub out calls to batchAndSendRequests.
            .provide([[matchers.call.fn(metrics.batchAndSendRequests), null]])
            // Dispatch six requests, with delays inserted in order to trigger
            // batch sends.
            .dispatch(requestAction)
            .dispatch(requestAction)
            .dispatch(requestAction)
            .delay(0)
            .dispatch(requestAction)
            .delay(0)
            .dispatch(requestAction)
            .dispatch(requestAction)
            .run()
            .then((result) => {
              const { effects } = result;
              // Verify the order of call dispatches.
              assert.deepEqual(effects.call, [
                delay(0),
github sovrin-foundation / connector-app / app / claim-offer / __tests__ / claim-offer-store.spec.js View on Github external
it('saga: saveSerializedClaimOffer', () => {
    const claimHandle = 1
    return expectSaga(
      saveSerializedClaimOffer,
      claimHandle,
      pairwiseConnection.identifier,
      uid
    )
      .provide([
        [
          matchers.call.fn(serializeClaimOffer, claimHandle),
          serializedClaimOffer,
        ],
        [
          matchers.call.fn(getClaimOfferState, claimHandle),
          claimOfferVcxInitialState,
        ],
      ])
      .put(
github sovrin-foundation / connector-app / app / lock / __tests__ / lock-store.spec.js View on Github external
it('check pin flow should work if correct pin is passed', () => {
    const pin = '123456'
    const salt = 'salt'
    const expectedPinHash = 'expectedPinHash'

    return expectSaga(checkPin, checkPinAction(pin))
      .provide([
        [matchers.call.fn(safeGet, IN_RECOVERY), null],
        [call(getHydrationItem, SALT), salt],
        [call(getHydrationItem, PIN_HASH), expectedPinHash],
        [matchers.call.fn(pinHash, pin, salt), expectedPinHash],
      ])
      .put(checkPinSuccess())
      .run()
  })
github source-academy / cadet-frontend / src / sagas / __tests__ / workspaces.ts View on Github external
test('loads CURVES library correctly', () => {
    const newExternalLibraryName = ExternalLibraryNames.CURVES;

    const symbols = externalLibraries.get(newExternalLibraryName)!;
    const library: Library = {
      chapter,
      external: {
        name: newExternalLibraryName,
        symbols
      },
      globals
    };

    return expectSaga(workspaceSaga)
      .put(actions.endClearContext(library, workspaceLocation))
      .dispatch({
        type: actionTypes.BEGIN_CLEAR_CONTEXT,
        payload: { library, workspaceLocation }
      })
      .silentRun()
      .then(() => {
        expect(loadLib).toHaveBeenCalledWith('CURVES');
        expect(getReadyWebGLForCanvas).toHaveBeenCalledWith('curve');
        globals.forEach(item => {
          expect(window[item[0]]).toEqual(item[1]);
        });
      });
  });
});
github popcodeorg / popcode / test / unit / sagas / user.js View on Github external
t.test('not dismissed during undo period, successful migration', assert => {
    testSaga(startAccountMigrationSaga, startAccountMigration())
      .next()
      .inspect(effect => {
        assert.deepEqual(
          effect,
          race({
            shouldContinue: delay(5000, true),
            cancel: take('DISMISS_ACCOUNT_MIGRATION'),
          }),
        );
      })
      .next({shouldContinue: true, cancel: null})
      .put(accountMigrationUndoPeriodExpired())
      .next()
      .select(getCurrentAccountMigration)
      .next(migration)
      .call(migrateAccount, firebaseCredential)
github popcodeorg / popcode / test / unit / sagas / ui.js View on Github external
test('userDoneTyping', assert => {
  testSaga(userDoneTypingSaga)
    .next()
    .put(userDoneTyping())
    .next()
    .isDone();
  assert.end();
});
github popcodeorg / popcode / test / unit / sagas / projects.js View on Github external
test('toggleLibrary', assert => {
  const scenario = new Scenario();
  const userId = 'abc123';
  const currentProject = project();
  const {projectKey} = currentProject;
  testSaga(toggleLibrarySaga, toggleLibrary(scenario.projectKey, 'jquery'))
    .next()
    .select(getCurrentProject)
    .next(currentProject)
    .select()
    .next(scenario.state)
    .call(getCurrentUserId, scenario.state)
    .next(userId)
    .call(getProject, scenario.state, {projectKey})
    .next(currentProject)
    .call(saveProject, userId, currentProject)
    .next()
    .put(projectSuccessfullySaved())
    .next()
    .isDone();
  assert.end();
});