reactjs-testutils

Trouble using TestUtils.Simulate to create a change event on an input element

[亡魂溺海] 提交于 2019-12-06 06:27:23
问题 I'm trying to write tests in jest for the examples shown in "Thinking in React" (http://facebook.github.io/react/docs/thinking-in-react.html) And I am having a hard time using TestUtils.Simulate to provide a change-event to the search input object. /** @jsx React.DOM */ jest.dontMock('../ProductTable.js'); jest.dontMock('../FilterableProductTable.js'); jest.dontMock('../SearchBar.js'); var React = require('react/addons'); var TestUtils = React.addons.TestUtils; var FilterableProductTable =

Simulating text entry with reactJs TestUtils

痞子三分冷 提交于 2019-12-05 12:37:22
问题 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 = 'a'; React.addons.TestUtils.Simulate.keyUp(nameInput); React.addons.TestUtils.findRenderedDOMComponentWithClass(component, 'has-error'); This doesn't seem to change the value of the bound textbox when I debug in the validator React.addons.TestUtils

Testing for mouse wheel events

安稳与你 提交于 2019-12-05 05:38:17
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) { (event.deltaY < 0 ) ? this.moveUp() : this.moveDown(); return false; } this.moveUp() / this.moveDown() simply sets the state of firstIndex The issue is that when I try to write a test for this functionality I can't get it to work. I'm almost 100% certain it has to do with the eventDetails object i'm passing in, but I don't know how to format it correctly. //

Simulate keydown on document for JEST unit testing

橙三吉。 提交于 2019-12-05 02:32:45
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 respond the keyboard action irrespective of the focussed element. EDIT: The question here is about simulating the event on the document or the document.body. All the examples are regarding an actual DOM node, that works fine but the document does not. Currently trying to do this: TestUtils.Simulate.keyDown(document, {keyCode : 37}); // handler not

Why React event handler is not called on dispatchEvent?

て烟熏妆下的殇ゞ 提交于 2019-12-04 18:29:37
问题 Consider the following input element in a React component: <input onChange={() => console.log('onChange')} ... /> While testing the React component, I'm emulating user changing the input value: input.value = newValue; TestUtils.Simulate.change(input); This causes 'onChange' to be logged, as expected. However, when the 'change' event is dispatched directly (I'm using jsdom): input.value = newValue; input.dispatchEvent(new Event('change')); the onChange handler is not called. Why? My motivation

Trouble using TestUtils.Simulate to create a change event on an input element

别等时光非礼了梦想. 提交于 2019-12-04 14:39:35
I'm trying to write tests in jest for the examples shown in "Thinking in React" ( http://facebook.github.io/react/docs/thinking-in-react.html ) And I am having a hard time using TestUtils.Simulate to provide a change-event to the search input object. /** @jsx React.DOM */ jest.dontMock('../ProductTable.js'); jest.dontMock('../FilterableProductTable.js'); jest.dontMock('../SearchBar.js'); var React = require('react/addons'); var TestUtils = React.addons.TestUtils; var FilterableProductTable = require('../FilterableProductTable.js'); var SearchBar = require('../SearchBar.js'); var PRODUCTS = [

Test a form with Jest and React JS TestUtils

心已入冬 提交于 2019-12-04 10:26:38
问题 I have a form with 3 radio buttons like follows (fake names): <form className="myForm" onSubmit={this.done}> <input className="myRadio" checked={ŧrue} type="radio" name="myRadio" onChange={this.change} value="value1" <input className="myRadio" type="radio" name="myRadio" onChange={this.change} value="value2" <input className="myRadio" type="radio" name="myRadio" onChange={this.change} value="value3" <input type="submit" className="submit" /> </form> And I am having very hard time trying to

Test a form with Jest and React JS TestUtils

自古美人都是妖i 提交于 2019-12-03 06:47:25
I have a form with 3 radio buttons like follows (fake names): <form className="myForm" onSubmit={this.done}> <input className="myRadio" checked={ŧrue} type="radio" name="myRadio" onChange={this.change} value="value1" <input className="myRadio" type="radio" name="myRadio" onChange={this.change} value="value2" <input className="myRadio" type="radio" name="myRadio" onChange={this.change} value="value3" <input type="submit" className="submit" /> </form> And I am having very hard time trying to test the onChange and the onSubmit events. inputs = TestUtils.scryRenderedDOMComponentsWithClass

Test React element height with Jest

天涯浪子 提交于 2019-12-01 18:03:35
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 the original content. In the Jest test environment my call to getDOMNode().scrollHeight does not appear to return anything. Here is a link to the repository with the code and failing test: https://github.com/mguterl/react-jest-dom-question Below is a simplified version of the code and test that illustrates the same issue: Simplified Code var

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

╄→гoц情女王★ 提交于 2019-12-01 17:49:58
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 state. The Error 1) Reduced Test Case - @current Tests that Fail when Component changes state and renders "before each" hook: Error: Invariant Violation: dangerouslyRenderMarkup(...): Cannot render markup in a worker thread. Make sure `window` and `document` are available globally before requiring React when unit testing or use React.renderToString