How to do jest testing in react native?

It’s because you are importing sum from your App file but it is not an exported method the way you wrote it.

You can do something like this:

export const sum = (a, b) => {
   alert(a + b);
   return a + b;

export const App = () => (
      onPress={() => {sum(1,2)}}

And use it like this in your test file:

import { sum } from '../App'

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);

It’s not particularly linked to React Native since you’re only trying to test a specific method, which can be use with any framework.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top