diff --git a/docs/recipes/react.md b/docs/recipes/react.md new file mode 100644 index 000000000..ba5ef19d7 --- /dev/null +++ b/docs/recipes/react.md @@ -0,0 +1,69 @@ +# React testing + +With 0.10.0, AVA stopped including your `.babelrc` (for reasons outlined in [this PR](https://github.com/sindresorhus/ava/pull/398)), which means you can't use JSX in your test/spec files. Note that this doesn't apply to your source files, they can still be written in JSX! + +The solution is just to use React's regular JS rendering methods, like `React.createElement`. + +So here's an example component we'd like to test: + +```JavaScript +import React, { PropTypes } from 'react'; +import { find } from 'lodash'; + +const FieldError = ({ errors, attribute, code, children }) => { + const result = find(errors, { attribute, code }); + + if (result) { + return { children }; + } + + /** + * Stateless components can't return null for now. React 0.15 is supposed to + * fix that, but for the time being use an empty or