mercredi 28 octobre 2020

React Native test function inside functional component using Jest

I have the following React Native functional component that has a function getNum() that I would like to test:

export default () => {
  function getNum(num) {
    return num;
  }
};

I have tried writing the following test:

it('test', () => {
  const test = renderer.create(<Test />).getInstance();
  expect(test.getNum(2)).toBe(2);
});

I get the following error:

TypeError: Cannot read property 'getNum' of null

Am I missing something?

Aucun commentaire:

Enregistrer un commentaire