0

i have a function living in my utils that isn't part of a component at all

that function calls other functions, how can I mock this to test the conditional?

const myfunc = () =>
  funcA().funcB() ? (
    <Route path="somewhere" component={somecomponent} />
  ) : (
    <Redirect to="/somewhere/else" />
  );

how can I mock funcA and funcB to get them to return true and false to hit the correct part of the conditional? also how can I test for route path props?

i have this in my test at the moment but it is not generating the correct results

const funcA = jest.fn();
const funcB = jest.fn();
funcA.mockReturnValue(funcB);
funcB.mockReturnValue(true);
The Walrus
  • 1,148
  • 6
  • 28
  • 46

1 Answers1

0

You can Mock function A and B as follows

const funcB=()=>true;

const funcA=()=>{return {funcB}};

funcA().funcB() //returns True

You can refer this to test a react Router.

How to test react-router with enzyme

Roopak Puthenveettil
  • 1,387
  • 2
  • 13
  • 27