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

Test React element height with Jest

I have a very simple React.js component that decorates a long block of markup with "Read more" / "Read less" functionality. I have a few tests with Jest working, however, I am unable to assert that the DOM element height is increasing to the size of…
Michael Guterl
  • 853
  • 2
  • 8
  • 13
8
votes
2 answers

How to test HTML of a rendered React component?

My React component has a suggestionRenderer property that allows to specify how the component is rendered. For example: function renderLocation(suggestion,…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
7
votes
1 answer

React 13.3 unmountComponentAtNode() Error: Target container is not a DOM element

I'm getting the following error in my testing suite when I upgrade from React 12.2 to React 13.3: Error: Invariant Violation: unmountComponentAtNode(...): Target container is not a DOM element. I'm using this blog post to test my code using…
YPCrumble
  • 26,610
  • 23
  • 107
  • 172
7
votes
1 answer

Testing for mouse wheel events

I've set up a simple function to handle mouse wheel events on a menu component I built. The component works fine, I'm trying to write a unit test around it and that is giving me an issue. component handler: handleWheel: function (event) { …
badAdviceGuy
  • 2,060
  • 1
  • 16
  • 12
6
votes
2 answers

Test window keydown event in Reactjs

The component I am writing needs to change its behaviour depending on whether ctrl is pressed or not. I use a window.onkeydown event but Simulate from React Test Utils doesn't allow me to dispatch events against window. I've also tried…
Javier Conde
  • 2,553
  • 17
  • 25
6
votes
2 answers

Error: Invariant Violation: dangerouslyRenderMarkup(...): Cannot render markup in a worker thread

React Tests Fails after set State causes second render Up until now testing has been going well with JSDOM and Mocha. So far have not had to test any components that change their state. I found my first issue testing a component that changes it's…
Tabbyofjudah
  • 1,973
  • 3
  • 17
  • 29
6
votes
2 answers

React.addons.TestUtils.Simulate.scroll is not working

I'm trying to simulate a scroll event with ReactJS and JSDOM. Initially I tried the following: var footer = TestUtils.findRenderedDOMComponentWithClass(Component, 'footer'); footer.scrollTop = 500; TestUtils.Simulate.scroll(footer.getDOMNode()); //I…
Alan Souza
  • 7,475
  • 10
  • 46
  • 68
6
votes
2 answers

Test React Form Submission With Jest & TestUtils

I'm having trouble testing a form submit event using React, TestUtils and Jest. I have a component that renders a
DOM element; the same component also has a method that handles the onSubmit event and logs a statement. My goal is to mock the…
cooncesean
  • 1,294
  • 2
  • 18
  • 26
5
votes
1 answer

Jest issue - ReactElement.js: Failed to get mock metadata

I've a very simple test /** @jsx React.DOM */ var store = require('../simpleStore'); var TestUtils = require('react/addons').addons.TestUtils; describe("my tests",function(){ it('simple test',function(){ var x=10, y=20; …
Sahas
  • 3,046
  • 6
  • 32
  • 53
4
votes
0 answers

ReactJS Component testing with mocked http calls

I've taken a ReactJS component (rendering the latest gist URL for a given user) from the React docs, and was wondering what is the best way to unit test such a component : The goals are Test in isolation (using mocked http calls) Use our existing…
ddewaele
  • 22,363
  • 10
  • 69
  • 82
4
votes
2 answers

How to test a React component that uses context like in react-router 2.0 with Jest 0.8.x

I had this problem in the past while using older versions of react-router which I solved using: stubRouterContext + a hacky way to access the component instance (using refs:…
Ferran Negre
  • 3,712
  • 3
  • 34
  • 56
4
votes
5 answers

Unit testing React component using Material UI Dialog

I am currently writing unit tests for my React + MaterialUi application. In my application I have a Dialog. I want to make sure depending on what button pressed on the dialog:
jonas.hartwig
  • 857
  • 3
  • 8
  • 19
4
votes
1 answer

How to test children components get proper context from parent's getChildContext()?

I have a component that has a getChildContext() method and children that receive that context which is derived from the props of the parent. How do I test that they have received it? Here is the code for the components... some tab components. The…
realisation
  • 475
  • 6
  • 19
4
votes
1 answer

Using scryRenderedComponentsWithType or findRenderedComponentWithType

I am trying to do some unit testing by using findRenderedComponentWithType and findRenderedComponentWithType to find components. However, I am having a bit of trouble. I have a shallow rendered component and within it, I want to find…
Liondancer
  • 15,721
  • 51
  • 149
  • 255
4
votes
2 answers

Find component using CSS selector in TestUtils

I'm writing some simple tests for my React components using TestUtils and I'm finding that both the TestUtils.FindRenderedDOMComponentWithClass and TestUtils.FindRenderedDOMComponentWithTag methods are pretty limiting. I'd like to find a component…
Kyle S.
  • 147
  • 2
  • 9