Created
March 8, 2019 00:29
-
-
Save nicksheffield/b8f6d5feeb097b48343cf7c7dcbe56b8 to your computer and use it in GitHub Desktop.
A quick method for testing hooks with react-testing-library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { render } from 'react-testing-library' | |
export default hookfn => { | |
const Comp = ({ children, args }) => children(hookfn(...args)) | |
const setup = (...args) => { | |
let output = {} | |
render( | |
<Comp args={args}> | |
{val => { | |
output = Object.assign(output, val) | |
return null | |
}} | |
</Comp> | |
) | |
return output | |
} | |
return setup | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment