Any examples on how to test react-native with expo and jest?

#1

I can’t seem to be able to run tests nor I can find any examples on how to test with jest and expo.

Could someone point me in the right direction?

I have this:

import { Text } from "react-native";
import React from "react";
import renderer from "react-test-renderer";

it("renders correctly", () => {
  const tree = renderer.create(<Text>Snapshot test!</Text>).toJSON();

  expect(tree).toMatchSnapshot();
});

but when I run the tests I get:

This is my package.json:

"scripts": {
  "test": "node_modules/.bin/jest"
},
"jest": {
  "preset": "jest-expo"
},
"devDependencies": {
  "jest-expo": "^28.0.0"
}
...
#2

Is the readme here sufficient?

#3

The test only works with the example that’s written there but It doesn’t work with the above example.

closed #4

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.

#5

i copied and pasted your test code into a new project and it worked. i think the issue is related to babel config somewhere. try making a new project from the tabs template and check out the setup there (alternatively, the template source is at https://github.com/expo/new-project-template)