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: http://facebook.github.io/react/docs/test-utils.html

89 questions
34
votes
6 answers

How to test React PropTypes through Jest?

I'm writing Jest tests for my React code and hoping to make use of/test the PropType checks. I am quite new to the Javascript universe. I'm using npm to install react-0.11.2 and have a simple: var React = require('react/addons'); In my tests. My…
MichaelJones
  • 1,120
  • 1
  • 11
  • 21
26
votes
14 answers

Testing React Select component

https://github.com/JedWatson/react-select I would like to use React-Select react component, but I need to add tests. I've tried several options I found with google, but nothing seems to work. I have the code below, but it's not causing a change…
Llewellyn
  • 381
  • 2
  • 5
  • 9
21
votes
4 answers

Calling setState in jsdom-based tests causing "Cannot render markup in a worker thread" error

I'm testing my React components under jsdom using my own tiny "virtual browser" utility. Works just fine, until I'm trying to setState. For example, when testing a children ages input control: describe('rendering according to the draft value',…
Ivan Krechetov
  • 17,548
  • 8
  • 45
  • 58
20
votes
3 answers

Why React event handler is not called on dispatchEvent?

Consider the following input element in a React component: console.log('onChange')} ... /> While testing the React component, I'm emulating user changing the input value: input.value =…
Misha Moroshko
  • 148,413
  • 200
  • 467
  • 700
18
votes
0 answers

Mocking file input in React TestUtils

I have a component with the following render function:- render: function() {
fbielejec
  • 2,972
  • 4
  • 21
  • 33
16
votes
3 answers

Simulate keydown on document for JEST unit testing

Using JEST to unit test a component that has a keydown listener attached to the document. How can I test this in JEST? How do I simulate the keydown event on the document? I need the event listener to be on the document since it is supposed to…
14
votes
2 answers

Simulating text entry with reactJs TestUtils

I want to be able to simulate a user typing into a text box using reactjs so that I can test my validation status messages. I have a react component which validates on keyUp Below is a simple example of what I've tried. nameInput.props.value =…
Not loved
  • 30,848
  • 21
  • 111
  • 180
13
votes
1 answer

Change element size using Jest

I have following code in my component var rect = ReactDOM.findDOMNode(this).getBoundingClientRect(); I use d3js and render graph in the component. But when I run test there are any svg tags. I assume that it happens because all rect's fields equals…
Gleb
  • 1,212
  • 2
  • 17
  • 33
12
votes
1 answer

Select option with React TestUtils Simulate

I have the following React components, and I want to select one of the selectElements in my select-block with TestUtils. How do I do that? var selectElements = ["type_a", "type_b"]; var SelectElement = React.createClass({ render: function() { …
andersem
  • 724
  • 1
  • 8
  • 18
12
votes
1 answer

Test a form with Jest and React JS TestUtils

I have a form with 3 radio buttons like follows (fake names):
Ferran Negre
  • 3,453
  • 3
  • 32
  • 55
11
votes
2 answers

Error: Invariant Violation: findAllInRenderedTree(...): instance must be a composite component

While writing the test case in JEST for React file I am getting this error. Following is my sample code: search_basr_test.js jest.autoMockOff(); global.React =…
Arif Usman
  • 1,078
  • 1
  • 11
  • 19
11
votes
4 answers

Unit testing react component that makes ajax calls using JEST

I've a react component that makes AJAX call in componentDidMount method. While I try to render it using React.addons.TestUtils, the component gets rendered without making AJAX call. How would I test react component using jest so that it makes AJAX…
alok mittal
  • 111
  • 1
  • 1
  • 3
9
votes
1 answer

what is adapter in enzyme

Any documentation on what's the purpose of adapter in enzyme testing library. import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; configure({ adapter: new Adapter() });
Sai Ram
  • 3,111
  • 2
  • 19
  • 30
9
votes
3 answers

React component using jQuery without require - jest unit tests

I have a very simple React mixin which uses jQuery to trigger an event MyMixin = { trackStructEvent: function () { args = Array.prototype.slice.call(arguments); $('body').trigger('myEvent', args); } module.exports = MyMixin This is…
Sam Ternent
  • 272
  • 1
  • 3
  • 13
7
votes
1 answer

React testing component prop change with enzyme

I am modifying an example found here: https://github.com/airbnb/enzyme/blob/master/docs/api/ReactWrapper/setProps.md class Foo extends React.Component { render() { return (
Daniel Billingham
  • 1,221
  • 4
  • 14
  • 22
1
2 3 4 5 6