Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Error testing a single component's propTypes with checkPropTypes multiple times #91

@brucewpaul

Description

@brucewpaul

While going through and updating to use the external prop-types package, I noticed that some of our tests were failing and couldn't figure out why. Eventually we found that the oddity in the tests were coming from the fact that the warning issued by the package is only called once, even if testing the component's propTypes with checkPropTypes multiple times. Take for example the following tests:

it('returns error if props[propName] is not passed', () => {
    const propValue = null;
    expect(() => PropTypes.checkPropTypes(Component.propTypes, { [propName]: propValue }, propName, componentName)).to.throw(Error);
});

it('returns error if any of the props[propName] is not a PropType.node', () => {
    const propValue = shallow(<div>{{}}</div>).props().children;
    expect(() => PropTypes.checkPropTypes(Component.propTypes, { [propName]: propValue }, propName, componentName)).to.throw(Error);
});

In this case, the first test passes as the package does warn (and we override console.warn/console.error to throw an error), but the second test fails as there isn't a warning, and thus an error isn't thrown.

We know that this is the case because if we change componentName to be a unique string in each case, the warning is displayed for each as expected.

The trouble here is that with using this external package, we're unsure as to how many false positives we have in our test suite due to this.

Should there a be a way to have the warning's call each time so that tests can test this more accurately?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions