2

For testing Im using JSDom, mocha, chai and ReactTestUtils.

One of my component got three radio button, that when a change is detected (onChange) will run a function.

Everything works in manual testing, but I cant seem to trigger the function when I use simulate.Click on it.

        var FrequencyFormInstance = ReactTestUtils.findRenderedComponentWithType(rootElement, FrequencyForm);
        var frequencyNode = ReactDom.findDOMNode(FrequencyFormInstance);

        var oneOfTheRadioButton = frequencyNode.children[1].children[2];

        ReactTestUtils.Simulate.click(oneOfTheRadioButton);

then some assert show me that the function inside the component was never ran, so it never detected the change (the click on the radio button).

any clue as to why?

user308553
  • 1,238
  • 4
  • 18
  • 32

1 Answers1

0

This is something that is discussed here: https://github.com/facebook/jest/issues/242

Essentially you need to use change as it is an input but also pass in the extra data.

var FrequencyFormInstance = ReactTestUtils.findRenderedComponentWithType(rootElement, FrequencyForm);
var frequencyNode = ReactDom.findDOMNode(FrequencyFormInstance);

var oneOfTheRadioButton = frequencyNode.children[1].children[2];

ReactTestUtils.Simulate.change(checkbox.getDOMNode(), {"target": {"checked": true}}); 
John
  • 29,788
  • 18
  • 89
  • 130