Questions tagged [react-test-renderer]

This package provides an experimental React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM or a native mobile environment.

This package provides an experimental React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM or a native mobile environment.

Essentially, this package makes it easy to grab a snapshot of the "DOM tree" rendered by a React DOM or React Native component without using a browser or jsdom. Read more about it here: https://github.com/facebook/react/tree/master/packages/react-test-renderer

164 questions
3
votes
0 answers

Jest snapshot test throws "Cannot read properties of null (reading 'scrollWidth')"

I'm trying to write a snapshot test for one of the component in my app. The component is built with some Antd components like Select. i get the following error. The tests import React from 'react' import renderer from 'react-test-renderer' import {…
3
votes
0 answers

fireEvent.press not working (React Native Testing Library)

I am writing unit tests for my React Native project. My main screen is WelcomScreen.js and inside it is following custom button created using TouchableOpacity:
3
votes
1 answer

Typescript error for React test Renderer JSON not having Children

I have created an expo app with the basic typescript template as documented. Installed all the requirements needed for testing and its types. I can run the test, and it does pass the test. However, I am getting an error on the IDE (VS code) for the…
3
votes
1 answer

TypeError: (0 , _native.createNavigatorFactory) is not a function

Trying to perform npm test on my React Native application, unit testing with Jest are working fine. However with react-test-renderer it complaining the following issue. FAIL __tests__/App-test.js ● Test suite failed to run TypeError: (0 ,…
Tommy Leong
  • 2,509
  • 6
  • 30
  • 54
3
votes
2 answers

Error when running unit test "You should not use outside a "

I have a unit test here and I am performing a click event. I am getting the error: Invariant failed: You should not use outside a describe("when the menu icon has been clicked", () => { test("the account menu should be…
3
votes
1 answer

TypeError: Cannot read property 'params' of undefined Jest Testing - React Native

I have created a test file to test my following "BiddingScreen", const BiddingScreen = ({ route, navigation }) => { const { currentBid } = route.params; return (
3
votes
3 answers

React Jest how to test if a span contains some certain text from mount snapshot?

I am testing a component that does not have any id for me to be able to select from Jest, my mounted component snapshot will be like

Drex
  • 3,346
  • 9
  • 33
  • 58

3
votes
1 answer

Error using 'react-test-renderer' - Cannot read property 'hasOwnProperty' of undefined

I'm trying to implement Jest in my react app, but when I import the react-test-renderer, I get the error message: TypeError: Cannot read property 'hasOwnProperty' of undefined The only line in my App.test.jsx file is: import TestRenderer from…
David Hope
  • 2,216
  • 16
  • 32
3
votes
1 answer

Can't get Jest expo app to work with react-navigation

I am trying to snapshot test with Jest, Expo, React Navigation and my whole app uses hooks only. I'd like to eventually make these into e2e tests where Jest clicks through and snapshot tests everything but I can't even get react navigation to…
3
votes
1 answer

How to mock a third party react-native component with jest?

I am using the NumericInput and it works fine when I run the application on my device. However, when I run jest, I get all kind of errors: TypeError: Cannot read property 'default' of undefined at new Icon…
3
votes
1 answer

React-Test-Render call component method

I have the following component: export const FormikInput: React.SFC = (props: Props) => { const handleChange = (value: string) => { // do something props.setFieldValue(props.key, value); return (
Anh Tuan Nguyen
  • 429
  • 1
  • 6
  • 18
3
votes
0 answers

Warning: Shallow renderer has been moved to react-test-renderer/shallow

I am getting following warnings while executing my unit test cases with jest in React app: Warning: Shallow renderer has been moved to react-test-renderer/shallow. Update references to remove this warning. Warning: ReactTestUtils has been moved to…
Peter
  • 10,492
  • 21
  • 82
  • 132
2
votes
1 answer

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely

Try to snapshot a Logo component but got an error that is not properait as far as i understand. Pleas help! logo.test.js import TestRenderer from 'react-test-renderer'; import Logo from '../components/Common/Logo'; describe('Snapshot Logo…
2
votes
0 answers

Apollo MockedProvider Immediately Returns Null

I am troubleshooting a failing React unit test that uses TestRenderer from react-test-renderer. My component queries a rest endpoint using GraphQL via the useQuery hook. If I wrap my component with and call .toJSON(), it immediately…
2
votes
1 answer

Jest warning "Function components cannot be given refs." with TypeScript Functional Component Setup

The current setup is React 18 with the current versions of webpack, babel, typescript, jest & using the MaterialUI component library. Running/building the application produces no error & the warning below only occurs during the component Jests test.…
1 2
3
10 11