diff --git a/README.md b/README.md index 7b41569c..c5e2c94d 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,9 @@ test('Fetch makes an API call and displays the greeting when load-greeting is cl // Arrange axiosMock.get.mockResolvedValueOnce({data: {greeting: 'hello there'}}) const url = '/greeting' - const {getByText, getByTestId, container} = render() + const {getByText, getByTestId, container, asFragment} = render( + , + ) // Act fireEvent.click(getByText('Load Greeting')) @@ -119,6 +121,8 @@ test('Fetch makes an API call and displays the greeting when load-greeting is cl expect(getByTestId('ok-button')).toHaveAttribute('disabled') // snapshots work great with regular DOM nodes! expect(container.firstChild).toMatchSnapshot() + // you can also use get a `DocumentFragment`, which is useful if you want to compare nodes across render + expect(asFragment()).toMatchSnapshot() }) ``` @@ -547,6 +551,38 @@ const usernameInputElement = getByTestId('username-input') > about `data-testid`s from the blog post ["Making your UI tests resilient to > change"][data-testid-blog-post] +#### `asFragment(): DocumentFragment` + +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. + +```javascript +import {render, fireEvent} from 'react-testing-library' + +class TestComponent extends React.Component { + constructor() { + super() + this.state = {count: 0} + } + + render() { + const {count} = this.state + + return