Questions tagged [reactjs-testutils]

Unit testing helpers for reactjs

ReactJs TestUtils are provided in the 'with-addons' react package and allow you to perform actions against a simulated DOM for the purposes of unit testing. See the documentation here.

87 questions
2
votes
2 answers

Testing React with Boostrap Modal on click

I've got this simple code from react bootstrap website... import {Modal} from 'react-bootstrap'; import React from 'react'; export default class ModalExperiment extends React.Component { constructor(props) { super(props); this.state =…
Tin Ng
  • 937
  • 2
  • 11
  • 25
2
votes
1 answer

How can I access inline style using React findDomNode function?

I am currently Jest to test React component, component's inline style would be changed according to different props value. this is an example about what I wanna do: let firstChild = TestUtils.findRenderedDOMComponentWithTag(renderedComponent,…
George Jor
  • 135
  • 7
2
votes
1 answer

Simulating drag drop with react testutils not working

I'm try to test my ReactJS mixin for drag and drop functionality using jasmine, karma and React TestUtils. No exception is thrown but when debugging it seems that the function bound to the event listener not being executed when the event is…
2
votes
1 answer

How to check if component has child component

I am using Jest to test a ReactJS app. How can one test if the view controller has the necessary child components present. For example, here is an example of the view controllers' render function: // App.js render: function() { var table; if…
medowlock
  • 1,469
  • 1
  • 19
  • 25
2
votes
1 answer

How to test React component without Browserify

I have a react application that doesn't uses the browserify tool. It means that the React variable is exported by the script of the react js lib called in the . // React variable is already available var MyComponent = React.createClass({});…
1
vote
2 answers

I am learning react and my code is working fine but how can i declare currDate single time to use it globally to use in useState

How can I declare currDate globally to use it in useState. The following code works just fine but wish to make it more efficient. Is there any better way to shorten the code? import React, { useState } from "react"; const Clock = () => { …
1
vote
1 answer

Testing functions directly in Functional component

Suppose we have a functional component as below. const Test: React.FC = () => { const isItemSelected = () => { console.log('Hi); }; return (
); }; And I want to invoke isItemSelected function directly while writing unit test…
Gowthamr.cs
  • 141
  • 2
  • 12
1
vote
1 answer

React Test Utils vs Selenium WebDriver

We have used React JS for front end and we need to write end to end tests. After researching online, we came across 2 options : 1. Selenium WebDriver 2. React Test Utils (https://reactjs.org/docs/test-utils.html) What I understood was that with…
j10
  • 2,009
  • 3
  • 27
  • 44
1
vote
1 answer

React testing button property disable

I cannot write correct test case for button property disable. I use TestUtils from react-addons-test-utils. I have very simple component: const propTypes = { disabled: PropTypes.func.isRequired }; class MyComponent extends Component { …
user
  • 4,410
  • 16
  • 57
  • 83
1
vote
1 answer

reactjs / jest : unable to populate react-apollo component with data using MockedProvider?

I have written simple react-apollo component which uses graphql query to retrieve data from schema. On execution component works fine but, when I am writing test case for this component using jest framework together with MockedProvider(i.e.…
1
vote
1 answer

Very high memory/cpu usage while testing React components with Karma in Chrome

Currently in my project I'm using Karma and Mocha, with React Test-Utils to test my react components. I currently have around 1200 tests, most of which are for my library of react components. When these tests run, chrome often exceeds 2gb of memory,…
CD-jS
  • 1,125
  • 1
  • 15
  • 32
1
vote
1 answer

react component test cannot find text

I am writing a test case for a particular component I created. The component is here import React, { PropTypes } from 'react'; import moment from 'moment'; const RouteHeader = ({ activeTab, isSearched, flight, results, departureDate, returnDate })…
Tarang Hirani
  • 560
  • 1
  • 12
  • 43
1
vote
3 answers

React component test keeps failing

I keep getting this error when testing my TodoList component: debug.html:38 Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. I'm not…
Funk Soul Ninja
  • 2,113
  • 3
  • 17
  • 27
1
vote
1 answer

Fake server response body should be string, but was undefined

I am trying to do unit tests at react components with mocha, chai and sinon. My first test worked, it is simple checking if component exists and if props are used correctly. Now I having trouble with ajax on tests. Here is my code: import * as React…
Alessander França
  • 2,697
  • 2
  • 29
  • 52
1
vote
0 answers

Testing react components componentDidMount, how do I render into a new document after each test?

Tests run, but they are rendering into the same document. On componentDidMount Style component appends CSS text to a style element in head with the class .reactive-style (know this is unorthodox and not idiosyncratic React). If .reactive-style does…
Joshua Robinson
  • 3,430
  • 1
  • 27
  • 35