facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

Warning: Invalid argument supplied to oneOfType, expected an instance of array. #287

Closed devTomek closed 5 years ago

devTomek commented 5 years ago
console.error node_modules/prop-types/factoryWithTypeCheckers.js:23
    Warning: Invalid argument supplied to oneOfType, expected an instance of array.
EnumCell.propTypes = {
    options: PropTypes.arrayOf(
        PropTypes.shape({
            value: PropTypes.string,
            label: PropTypes.string
        })
    ),
};

EnumCell.defaultProps = {
    options: [],
};
it("should render select with given options", () => {
        props = {
            ...props,
            options: [
                { value: "test1", label: "test1" },
                { value: "test2", label: "test2" },
                { value: "test3", label: "test3" },
            ]
        };

        wrapper.setProps(props);

        const options = wrapper.find("EnumCell").props().options;

        expect(options).toEqual(props.options);
});

Is this package error or my fault?

ljharb commented 5 years ago

Are you sure that EnumCell is where the error is coming from? You're not using PropTypes.oneOfType anywhere in that code.

It seems like it's coming from wrapper, not from EnumCell.

devTomek commented 5 years ago

Sorry for late response, I have this error only in tests. In developing console and browser console it is fine. But I will check it again.

devTomek commented 5 years ago

I checked. I pass everywhere an array. I repeat, this warning appears only in terminal run with jest.

ljharb commented 5 years ago

It's probably https://github.com/facebook/jest/issues/2549 - a bug in jest.

devTomek commented 5 years ago

Maybe. I can't reproduce it in code sandbox, so I close this topic in hope it will be fixed in other. Thanks for your time :)

ambujThalesOW commented 1 year ago

Did anyone find any solution to fix it?

ljharb commented 1 year ago

@ambujThalesOW not without a repro repo, unfortunately.