@testing-library/react#findAllByRole TypeScript Examples
The following examples show how to use
@testing-library/react#findAllByRole.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Feed.spec.tsx From apps with GNU Affero General Public License v3.0 | 6 votes |
it('should replace placeholders with posts and ad', async () => {
renderComponent();
await waitForNock();
const elements = await screen.findAllByTestId('postItem');
expect(elements.length).toBeGreaterThan(0);
await Promise.all(
elements.map(async (el) =>
// eslint-disable-next-line testing-library/prefer-screen-queries
expect((await findAllByRole(el, 'link'))[0]).toHaveAttribute('href'),
),
);
await waitFor(async () => {
const el = await screen.findByTestId('adItem');
// eslint-disable-next-line testing-library/prefer-screen-queries
expect(await findByRole(el, 'link')).toHaveAttribute('href', ad.link);
});
});
Example #2
Source File: TagsFilter.spec.tsx From apps with GNU Affero General Public License v3.0 | 6 votes |
it('should show the tags for a open category', async () => {
const { baseElement } = renderComponent();
await waitFor(() => expect(baseElement).not.toHaveAttribute('aria-busy'));
const {
parentElement: { parentElement: summary },
} = await screen.findByText('Frontend');
summary.click();
const buttonDiv = await screen.findByTestId('tagCategoryTags');
expect(buttonDiv).toBeVisible();
// eslint-disable-next-line testing-library/prefer-screen-queries
const buttons = await findAllByRole(buttonDiv, 'button');
const tags = ['react', 'webdev', 'vue', 'golang'];
buttons.map((button, index) =>
expect(button).toHaveTextContent(`#${tags[index]}`),
);
});