facebook / prop-types

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

Export resetWarningCache #178

Closed patsplat closed 5 years ago

patsplat commented 6 years ago

When testing code using PropTypes, warnings fail unexpectedly due to caching behavior. It would be useful for resetWarningCache to be part of the publicly exported API.

patsplat commented 6 years ago

Thanks for the 👍

This addition is also intended to make spying console.error for expected warnings reliable. Currently mocha --watch fails on rebuilds.

ljharb commented 6 years ago

cc @aweary

patsplat commented 6 years ago

Hi! Any updates or feedback on this PR?

patsplat commented 6 years ago

Closing due to inactivity. If you are interested in this feel free to reopen.

ljharb commented 6 years ago

Please reopen this; inactivity is irrelevant.

patsplat commented 6 years ago

@ljharb any suggestions on next steps for this PR?

ljharb commented 6 years ago

Unfortunately we have to wait for the maintainers to take a look.

gaearon commented 6 years ago

Is there any specific reason it's on checkPropTypes, and not on the PropTypes object itself?

I'm worried if attaching things to functions can mess with uglify/rollup "pure" code detection. Not that it matters for this piece of code but still.

ljharb commented 6 years ago

It does seem useful to me to have it tucked away somewhere - devs are less likely to casually use it that way.

patsplat commented 6 years ago

Implemented on checkPropTypes as that is the unit whose state is modified.

patsplat commented 6 years ago

Happy if library maintainers want to move the interface around, but figured it could start in the most naive spot first.

uniphil commented 6 years ago

This would be awesome! It would make eg. https://github.com/ratehub/check-prop-types obsolete, which would make me (its creator) very happy.

patsplat commented 6 years ago

@gaearon changed the public interface to PropTypes.resetWarningCache. Still need to reach inside checkPropTypes to clear the cache.

Are there any other recommended changes?

uniphil commented 5 years ago

💃

patsplat commented 5 years ago

Thanks @ljharb !