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

React / Unit Test (Jest) click method with preventDefault

So I got a little issue I am stumped with... I have a Link component which will either go to a specific route via a to prop, if a certain condition is met. If that condition is not met, that link, when clicked, will do something else (launch a…
Lushmoney
  • 412
  • 11
  • 26
0
votes
1 answer

testing multiple HOC composed with recompose

I have a setup where I have a main container that is composed with multiple HOC using recompose. The HOC in use are; WithPageWrapper, WithLoading, WithError Composed like this: compose( withPageWrapper, withLoading, …
chinds
  • 1,761
  • 4
  • 28
  • 54
0
votes
1 answer

Random Jest Test Failures with error cannot read property of undefined

I am facing random test failures when running Test Suite with an exception of 'cannot read property of undefined' I am guessing it has something to do with race conditions happening somewhere but to my knowledge wherever the code failure points i…
anzie001
  • 231
  • 3
  • 12
0
votes
0 answers

how to snapshot from component created with material ui styles in way that styles would be in snapshot

I am using material-UI in my react web app. I want to test my component with jest in way that styles would be saved in snapshot of component like what jest-styled-component do for styled-component but I cant. you can see my sample project in…
Shahab Emami
  • 324
  • 1
  • 7
0
votes
1 answer

Test for pseudo class using Jest and React-test-renderer

I have a few hover pseudo classes in css and want to run a test and check if they are behaving properly. Is this possible with Jest? Apologies for my lack of knowledge here I'm only a day in using Jest. Css: .my-btn--lg.my-btn--brand.hover,…
user992731
  • 3,400
  • 9
  • 53
  • 83
0
votes
1 answer

Shallow testing error - Method “props” is meant to be run on 1 node. 0 found instead

I am doing shallow testing. Here is my container component code: class jcpenney1 extends Component { render() { const formId = uuidv1(); return (
developerExecutive
  • 89
  • 1
  • 2
  • 11
0
votes
1 answer

Sinon: Test React component method is calling function pass as a prop (Mocha + Chai + Sinon is being used for unit test)

I have a react component which has a method export class Hit extends React.Component { constructor(props) { super(props); this.triggerClick= this.triggerClick.bind(this); } triggerClick(event) { …
Vicky
  • 624
  • 2
  • 12
  • 35
0
votes
1 answer

Karma test in React app , failing with "TypeError: (0 , _expect2.default)(...).toExist is not a function"

I am new to React, and facing this failing test issue in my app (FilterItems component). Would greatly apprecitate any guidance or help. Here's my simple FilterItems component. import React, { Component } from 'react'; class FilterItems extends…
Rohan_Paul
  • 1,504
  • 3
  • 29
  • 36
0
votes
1 answer

Keep "this" context when mocking Promise in function on component

I am having an issue where I am not able to reference this keyword via Jest when testing some logic in my componentDidMount method. So once I am inside the promise response, when I hover over this in this.props (or this.setState), it just shows…
Shawn
  • 2,355
  • 14
  • 48
  • 98
0
votes
2 answers

Jest test using react-test-renderer is inserting undefined attribute value into the DOM

I briefly tried to find this in the react-test-renderer source code, but wasn't able to locate it. Recall that in React, component element attributes whose values are undefined are not rendered in the DOM. I.e., given bat = undefined and
icfantv
  • 4,523
  • 7
  • 36
  • 53
0
votes
1 answer

How to use babel-plugin-rewire with React?

I'm seeing this error: ✖ should dispatch profileAction PhantomJS 1.9.8 (Linux 0.0.0) TypeError: 'undefined' is not a function (evaluating '_Header2.default.__Rewire__('profileAction', function (a) { a(); })') at…
-1
votes
1 answer

How to test function which call api?

How to test a function which call get API and output a response. I tried but I am able to test initial data which is in state , but I want to know how to test the function which updates the initial state when the API is called . code Example what I…
-1
votes
1 answer

`simulate` - Fails on testing, Not able to figure out the issue

I do a simple testing using jest, all works fine expect a single issue. I am getting an error as expect(wrapper.find("textarea").prop("value")).toEqual("new comment"); fails. not able to figure out the issue. any one help me? here is my test code…
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
-2
votes
1 answer

getById is not a function

When I try to simulate a click I am getting the error in the subject line. My whole test file: import '@testing-library/jest-dom' import * as React from 'react'; import TestRenderer, {act} from 'react-test-renderer'; import { fireEvent, render }…
RandomDeveloper
  • 833
  • 2
  • 9
  • 31
1 2 3
10
11