Code Monkey home page Code Monkey logo

Comments (8)

neurosnap avatar neurosnap commented on June 9, 2024

Hi!

Could you please share your jest test? Thanks!

from redux-saga.

komalharmale avatar komalharmale commented on June 9, 2024

//App-test.js

import watchCounterIncrease from '../MyAssets/Redux/saga/saga';
jest.mock('redux-saga/effects');

describe('App Screen', () => {
const result=watchCounterIncrease();
console.log(result.next().value);
console.log(result.next());
})

///Here console returning result as
console.log
undefined

  at log (__tests__/App-test.js:29:11)

console.log
  { value: undefined, done: true }

  at log (__tests__/App-test.js:30:11)

from redux-saga.

komalharmale avatar komalharmale commented on June 9, 2024

Any suggestion?

from redux-saga.

Andarist avatar Andarist commented on June 9, 2024

Please always try to share a repro case in a runnable form - either by providing a git repository to clone or a codesandbox. OSS maintainers usually can't afford the time to set up the repro, even if exact steps are given.

from redux-saga.

komalharmale avatar komalharmale commented on June 9, 2024

https://codesandbox.io/s/redux-saga-counter-example-forked-32wp08?file=/index-test.js

from redux-saga.

neurosnap avatar neurosnap commented on June 9, 2024

@komalharmale You don't want to test watchCounterIncrease because that just runs takeLatest. Saga functions -- without the redux-saga middleware -- don't activate any side-effects, they just describe the side-effects to activate.

Here's an article I wrote describing it in more detail: https://bower.sh/simplify-testing-async-io-javascript

If you want to test, when a user clicks a button and it increments the counter the user should see the number 2, then you need to write an integration test that fully sets up your redux store (with redux-saga) as well as your react/react-native app, then simulate clicks in your app, and finally test what number displays on the screen.

If you just want to test the saga increaseAsync then you should run it as a standalone generator like you were doing inside your code sandbox.

For example:

import { delay, put } from "redux-saga/effects";
import { incrementAsync } from "./sagas/index";

describe("incrementAsync", () => {
  test("should call the sampleOne function", () => {
    const iter = incrementAsync();
    expect(iter.next().value).toEqual(delay(1000));
    expect(iter.next().value).toEqual(put({ type: "INCREMENT" }));
  });
});

I hope that was helpful but feel free to continue chatting. We also have a discord for more realtime help: https://discord.gg/AKz29HvK2h

from redux-saga.

komalharmale avatar komalharmale commented on June 9, 2024

@neurosnap Thank you for your support, but my concern is if we try to console this value then it is returning as undefined.
iter.next().value as well as delay(1000) is returning as undefined that is the reason the test cases are passing because the both value having undefined as result but in actual it's not giving as expected output.

This Redux-saga/effects not works while doing testing using Jest in React-Native.
If we Run normally like npx react-native run-android then it's work properly but when we run 'npm jest the above result in console print as undefined

from redux-saga.

komalharmale avatar komalharmale commented on June 9, 2024

closing as issue is not related to the this library

from redux-saga.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.