Tabnine Logo For Javascript
SagaTester
Code IndexAdd Tabnine to your IDE (free)

How to use
SagaTester
in
redux-saga-tester

Best JavaScript code snippets using redux-saga-tester.SagaTester(Showing top 4 results out of 315)

origin: reime005/react-saga-testing

describe("root saga", () => {
 it("should handle 4 button clicks one after another", async () => {
  const sagaTester = new SagaTester({
   reducers: rootReducer
  });

  sagaTester.start(rootSaga);

  sagaTester.dispatch(queuedSagaAction());
  sagaTester.dispatch(queuedSagaAction());
  sagaTester.dispatch(queuedSagaAction());
  sagaTester.dispatch(queuedSagaAction());

  await delay(5000); // wait for 4 request * max 1sec each

  const state = sagaTester.getState();

  expect(state.exampleReducer.counter).toEqual(4);
 }, 30000);
});
origin: boris-pokorny/react-example

test("filter saga", () => {
 const sagaTester = new SagaTester({
  initialState: {},
  reducers: {
   filter: filter,
   prices: prices,
  },
 });

 sagaTester.start(watchPeriod);

 sagaTester.dispatch(symbolSelected("S"));
 sagaTester.dispatch(periodSelected("W"));

 const state = sagaTester.getState();
 expect(state.filter).toEqual({
  period: "W",
  symbol: "S",
 });

 expect(state.prices.loading).toEqual(true);
});
origin: boris-pokorny/react-example

test("search saga", async () => {
 const delay = (t) => new Promise((res) => setTimeout(() => res(), t));
 const sagaTester = new SagaTester({
  initialState: {},
  reducers: {
   search: search,
  },
 });

 const mockSuccessResponse = {
  bestMatches: [],
 };
 const mockJsonPromise = Promise.resolve(mockSuccessResponse);
 const mockFetchPromise = Promise.resolve({
  json: () => mockJsonPromise,
 });
 jest.spyOn(global, "fetch").mockImplementation(() => mockFetchPromise);

 sagaTester.start(watchSearch);

 sagaTester.dispatch(searchSymbol("S"));
 expect(global.fetch).toHaveBeenCalledTimes(1);

 await delay(0);
 expect(global.fetch).toHaveBeenCalledTimes(1);
 expect(sagaTester.getState().search.options).toEqual([]);
 expect(sagaTester.wasCalled(types.SYMBOL_FOUND)).toEqual(true);
});
origin: boris-pokorny/react-example

test("prices saga", async () => {
 const delay = (t) => new Promise((res) => setTimeout(() => res(), t));
 const sagaTester = new SagaTester({
  initialState: {},
  reducers: {
   filter: filter,
   prices: prices,
  },
 });

 const mockSuccessResponse = {
  "Time Series": {},
 };
 const mockJsonPromise = Promise.resolve(mockSuccessResponse);
 const mockFetchPromise = Promise.resolve({
  json: () => mockJsonPromise,
 });
 jest.spyOn(global, "fetch").mockImplementation(() => mockFetchPromise);

 sagaTester.start(watchPrices);

 sagaTester.dispatch(fetchPrices());
 expect(sagaTester.getState().prices.loading).toEqual(true);
 expect(global.fetch).toHaveBeenCalledTimes(1);

 await delay(0);
 expect(global.fetch).toHaveBeenCalledTimes(1);
 expect(sagaTester.getState().prices.data.labels).toEqual([]);
 expect(sagaTester.wasCalled(types.PRICES_FETCHED)).toEqual(true);
});
redux-saga-tester(npm)SagaTester

Most used redux-saga-tester functions

  • SagaTester.dispatch
  • SagaTester.getState
  • SagaTester.start
  • SagaTester.wasCalled

Popular in JavaScript

  • q
    A library for promises (CommonJS/Promises/A,B,D)
  • lodash
    Lodash modular utilities.
  • express
    Fast, unopinionated, minimalist web framework
  • superagent
    elegant & feature rich browser / node HTTP with a fluent API
  • winston
    A logger for just about everything.
  • async
    Higher-order functions and common patterns for asynchronous code
  • fs-extra
    fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as mkdir -p, cp -r, and rm -rf.
  • fs
  • webpack
    Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJavascript Code Index
Get Tabnine for your IDE now