Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactoring asFragment example to use hooks
  • Loading branch information
pedroapfilho committed Jul 25, 2019
commit 6b06e2288005f08f62eeeb793faa6a8df56e969a
22 changes: 8 additions & 14 deletions docs/react-testing-library/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,17 @@ Returns a `DocumentFragment` of your rendered component. This can be useful if
you need to avoid live bindings and see how your component reacts to events.

```jsx
import React, { useState } from 'react'
import { render, fireEvent } from '@testing-library/react'

class TestComponent extends React.Component {
constructor() {
super()
this.state = { count: 0 }
}

render() {
const { count } = this.state
const TestComponent = () => {
const [count, setCounter] = useState(0)

return (
<button onClick={() => this.setState({ count: count + 1 })}>
Click to increase: {count}
</button>
)
}
return (
<button onClick={() => setCounter(count => count + 1)}>
Click to increase: {count}
</button>
)
}

const { getByText, asFragment } = render(<TestComponent />)
Expand Down