React-select: Testing - RangeError: Maximum call stack size exceeded

Created on 9 Mar 2015  路  5Comments  路  Source: JedWatson/react-select

I'm using the react-select component in my application and whenever it is referenced in my Jest tests I get an error that says "RangeError: Maximum call stack size exceeded".

Here is a basic test I've written using Jest based on the react-select example.

/** @jsx React.DOM */
'use strict';
jest.autoMockOff();

var React = require("react/addons");
var Select = require("react-select");
var TestUtils = React.addons.TestUtils;

describe("Select test", function() {

    var Select = require('react-select');

    var options = [
        { value: 'one', label: 'One' },
        { value: 'two', label: 'Two' }
    ];

    function logChange(val) {
        console.log("Selected: " + val);
    }

    // Render an instance of the component
    var instance = TestUtils.renderIntoDocument(
        <Select
            name="form-field-name"
            value="one"
            options={options}
            onChange={logChange}/>
        );
});

By simplifying the test to this level, I can assume the range error is happening within react-select. I also see Issue #73 there are no tests for react-select.

Does anyone else have a similar issue? I'm quite surprised the basic example implementation of the component won't pass a simple unit test.

Most helpful comment

i am getting the Maximum call stack size exceeded in react-native. please provide the solution .

Thanks in advance
Nishant Singh

All 5 comments

@mattdell I'm quite surprised too. It sounds like the test is firing off some kind of infinite loop (that's usually what leads to RangeErrors) - maybe it's something to do with the mock interfaces? ...because it doesn't seem to happen in the browser. I'm not familiar with using jest or React.TestUtils (both things I've been meaning to get to).

As I just mentioned in #73 any help getting tests in place for React-Select would be greatly appreciated.

@JedWatson I've opened a PR for this. https://github.com/JedWatson/react-select/pull/107

Thanks for your help with this @mattdell. I've tracked down the issue in the autosize-input component that was causing the infinite loop - it had to do with the logic that detects the width of the sizer element (which is mocked by Jest but not actually available).

Having fixed that, bumped all the versions and built a new release the tests now work as expected, so you should be able to test successfully in your own project now too.

@JedWatson Excellent. Glad I could help!

i am getting the Maximum call stack size exceeded in react-native. please provide the solution .

Thanks in advance
Nishant Singh

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pablote picture pablote  路  3Comments

steida picture steida  路  3Comments

juliensnz picture juliensnz  路  3Comments

x-yuri picture x-yuri  路  3Comments

MalcolmDwyer picture MalcolmDwyer  路  3Comments