Created
November 20, 2019 07:06
-
-
Save andiwinata/94ccedb376f925e3eacbf35885bac008 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { render, fireEvent, waitForElementToBeRemoved, prettyDOM } from '@testing-library/react'; | |
const { getByText, queryByText } = render( | |
<Component /> | |
); | |
const button = getByText(/Remove [0-9]+ projects? from this migration/); | |
fireEvent.click(button); | |
// click the remove project button | |
fireEvent.click(getByText('Remove project')); | |
expect(onRemoveProjectSpy).toHaveBeenNthCalledWith(1, ['serverKey']); | |
// wait for element to be gone | |
await waitForElementToBeRemoved(() => queryByText(modalText)); | |
expect(queryByText(modalText)).toEqual(null); | |
// handle react hook using `act()` | |
const mockSearchText = 'this is a mock search text'; | |
act(() => { | |
userEvent.type(getByPlaceholderText('Search for name'), mockSearchText); | |
}); | |
// find closest node - part of DOM api | |
expect(queryByText(modalText).closest('button')).toMatchInlineSnapshot(null); | |
// debugging | |
console.log(prettyDOM(queryByText(modalText))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment