Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49237

Jest conditional rendering based on usestate

$
0
0

this is my project code:

const [ipData, setIpData] = React.useState();

const [operationsLoader, setOperationsLoader] = React.useState(true);

const [operations, setOperations] = React.useState();

const [toRender, setToRender] = useState(false);

const [modalOpen, setModalOpen] = useState(false);

const [loaded, setLoaded] = React.useState(false);

const [allowed, setAllowed] = React.useState(false);

const tableRef = React.createRef();

and the component returing the html ,when loaded and allowed are set to true, by doing this and changing these states in my testcase, i am getting error:

Should have a queue. This is likely a bug in React. Please file an issue.

  84 |   const [operations, setOperations] = React.useState([]);
  85 |
> 86 |   const [toRender, setToRender] = useState(false);
     |                                   ^
  87 |   const [modalOpen, setModalOpen] = useState(false);

this is the code:

const useStateSpy = jest.spyOn(React, ‘useState’);
const setLoadingMock = jest.fn();
useStateSpy.mockImplementationOnce((loaded) => [loaded=“true”, setLoadingMock]);
useStateSpy.mockImplementationOnce((allowed) => [allowed=“true”, setLoadingMock]);

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 49237

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>