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
0
votes
1 answer

How to write unit test for Material UI slider? "Error: Cannot read property 'addEventListener' of null" thrown when attempting to render component

Trying to test the Material-UI Slider with Reat-Test-Renderer gets an error: Uncaught [TypeError: Cannot read property 'addEventListener' of null] Codesandbox Link import React from "react"; import { Slider } from "@material-ui/core"; import…
0
votes
1 answer

Using react-test-renderer w/ styled-components & Theme (React Native)

I have a styled-component that is using styled-system and it is working perfectly but when i go to test the component i can't seem to get it to populate the styles correctly from the Theme. It's strange because if i apply a prop like marginLeft={1}…
0
votes
1 answer

I cant test my Counter component a snapshot test

I used create-react-app to setup my react app. I was trying to test the Counter component but this error keeps happening I don't really understand what the error is can you please help me. import React from 'react'; import renderer from…
Michale Rezene
  • 350
  • 2
  • 12
0
votes
0 answers

Unable to write unit test cases for FHIR client api calls

I hava component Componnent1 and inside the componentDidMount i am having the below code:- const key1 = sessionStorage.getItem("key1"); FHIR.oauth2 .ready() .then((client) => client.request("/" + key1, { …
0
votes
1 answer

Testing function in a functional component

I have created a card component and has written test cases for this but on looking into test coverage number I found branch coverage for this component is 50%. And the part which is missing under test cases is testing of else part in onPress…
0
votes
1 answer

React unit test for Context and Reducer

I have created a LauoutContext.js for my application needs. Also used router location to get the URL / pathname. And passing reducer to child. JS File: LayoutContext.js import React, { createContext, useReducer } from 'react' import PropTypes from…
0
votes
1 answer

How can I test axios itself with mocking it?

I've just started learning react unit testing and the whole mock thing is confusing for me and I couldn't understand it . I'm using axios to fetch data and display it in app component here : const [ data, setData ] = React.useState(null); …
0
votes
2 answers

Testing Formik validate function with react-test-renderer

I'm trying to test my validate function with react-test-renderer via onChange and onBlur. Here is a simplified test: import renderer, { act } from 'react-test-renderer'; const byTypeAndName = (type, name) => elem => elem.type === type &&…
Danielle Madeley
  • 2,616
  • 1
  • 19
  • 26
0
votes
1 answer

How to test onPress for an Icon in React Native using Jest

In my program, I have a touchable icon that that sets a password field from hidden to visible, I need to test that when the icon is pressed, the password becomes visible. I have tried the…
LondonMassive
  • 367
  • 2
  • 5
  • 20
0
votes
3 answers

Element type is invalid - Export default and default import

I'm writing tests for my components, the components work fine in the application. Importing and consuming them works great but getting them to work with react-test-renderer has not been as great. For example, I have a social component that reads…
chrisotto6
  • 150
  • 1
  • 11
0
votes
1 answer

Mocking props from HOC in react for snapshot tests

I am trying to appropriately mock props for a simple sign out button component. The only prop in this component is the firebase prop which is coming from a Higher Order Component (HOC) called withFirebase. import React from 'react'; import {…
0
votes
0 answers

Writing tests with testing-library depends on implementation details of my UI library

I am using @testing-library to test my React project which uses Material-UI as it's main UI library. As @testing-library suggests, it's main philosophy is to test the application in the exact same way a user would use it. e.g click the button which…
0
votes
1 answer

how to test input value controlled by Redux state using @testing-library/react and react-test-renderer?

Using @testing-library/react,I am trying to test whether the input value is being by fireEvent or not. But Facing a problem, its always returning blank.As the value is controlled by the redux store. Here is the code:
0
votes
1 answer

React-bootstrap Typeahead does not work with Jest snapshots

I have a very simple AsyncTypeahead example from the API documentation : import {AsyncTypeahead} from "react-bootstrap-typeahead"; import React, {Component} from "react"; class AsyncTest extends Component { …
Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225
0
votes
0 answers

`this` isn't set to current object in monkey patched prototype method

I am trying to monkey patch an object created by react-test-renderer to add a .findById(testID) method, but inside the object I can't access other methods on the object. Here is the relevant code in my test file. import renderer from…
1 2 3
10
11