Skip to content

Instantly share code, notes, and snippets.

@nicksheffield
Created March 8, 2019 00:29
Show Gist options
  • Save nicksheffield/b8f6d5feeb097b48343cf7c7dcbe56b8 to your computer and use it in GitHub Desktop.
Save nicksheffield/b8f6d5feeb097b48343cf7c7dcbe56b8 to your computer and use it in GitHub Desktop.
A quick method for testing hooks with react-testing-library
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