Skip to content

Instantly share code, notes, and snippets.

@turadg
Last active April 13, 2018 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turadg/9bcf08a7279e82a030a645250639fe6e to your computer and use it in GitHub Desktop.
Save turadg/9bcf08a7279e82a030a645250639fe6e to your computer and use it in GitHub Desktop.
Jest setup file to stop React 15.5 createClass / PropTypes deprecation warnings
import React from 'react';
/**
* Since React v15.5, there's a warning printed if you access `React.createClass` or `React.PropTypes`
* https://reactjs.org/blog/2017/04/07/react-v15.5.0.html#new-deprecation-warnings
*
* `import * as React from 'react'` is required by Flowtype https://flow.org/en/docs/react/types/ ,
* but the * causes both those deprecated getters to be called.
* This is particularly annoying in Jest since every test prints two useless warnings.
*
* This file can be used as a Jest setup file to simply delete those features of the `react` package.
* You don't need the deprecation warning. Your tests will simply fail if you're still using the old ways.
* https://facebook.github.io/jest/docs/en/configuration.html#setupfiles-array
*/
delete React.createClass;
delete React.PropTypes;
@seanf
Copy link

seanf commented Jan 19, 2018

I know gist notifications are pretty much non-existent, but thank you @turadg! Handy for TypeScript migrations too.

@turadg
Copy link
Author

turadg commented Apr 13, 2018

I ended up back here and saw your comment @seanf. Not that you'll get this notification, but if you end up here again: thanks for your comment. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment