How to use the @testing-library/react.within function in @testing-library/react

To help you get started, we’ve selected a few @testing-library/react examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / @testing-library / react_v8.x.x / flow_v0.104.x- / test_react_v8.x.x.js View on Github external
it('should have getAllByPlaceholderText', () => {
    within(container).getAllByPlaceholderText('1');
  });
github kentcdodds / react-testing-library-course / src / __tests__ / portals.js View on Github external
test('modal shows the children', () => {
  render(
    
      <div data-testid="test">
    ,
  )
  const {getByTestId} = within(document.getElementById('modal-root'))
  expect(getByTestId('test')).toBeInTheDocument()
})
</div>
github flow-typed / flow-typed / definitions / npm / @testing-library / react_v8.x.x / flow_v0.104.x- / test_react_v8.x.x.js View on Github external
it('should have queryByDisplayValue', () => {
    within(container).queryByDisplayValue('1');
  });
github codefordenver / members / src / testUtils.tsx View on Github external
export function getQueries(container = document.body) {
  return {
    ...within(container),
    updateTextInput: updateTextInput.bind(null, container),
    getButtonByText: getButtonByText.bind(null, container)
  };
}
github styleguidist / react-styleguidist / src / client / rsg-components / StyleGuide / StyleGuide.spec.tsx View on Github external
test('should render a sidebar if showSidebar is not set', () =&gt; {
	const { getByTestId } = render(
		
	);
	const sidebar = within(getByTestId('sidebar'));
	const links = sidebar.getAllByRole('link');
	expect(links.map((node: any) =&gt; node.href)).toEqual([
		'http://localhost/#foo',
		'http://localhost/#bar',
	]);
	expect(links.map(node =&gt; node.textContent)).toEqual(['Foo', 'Bar']);
});
github habx / thunder-ui / src / confirm / confirm.spec.tsx View on Github external
it('should display two confirm modals in chronological order if called twice', () =&gt; {
    const { getAllByTestId } = render()

    act(() =&gt; {
      confirm(MESSAGE_1)
      confirm(MESSAGE_2)
    })

    const notifications = getAllByTestId('confirm-modal-container')
    expect(notifications).toHaveLength(2)
    expect(
      within(notifications[0]).getByTestId('confirm-modal-content').textContent
    ).toEqual(MESSAGE_1)
    expect(
      within(notifications[1]).getByTestId('confirm-modal-content').textContent
    ).toEqual(MESSAGE_2)
  })
github habx / thunder-ui / src / Drawer / Drawer.spec.tsx View on Github external
null}
          triggerElement={
            <button data-testid="drawer-trigger-element">show</button>
          }
        &gt;
          <div data-testid="content">CONTENT</div>
        
      )

      fireEvent.click(getByTestId('drawer-trigger-element'))
      fireEvent.click(getByTestId('drawer-overlay'))

      const modalContainer = queryByTestId('drawer-container') as HTMLElement
      expect(modalContainer).toBeTruthy()
      expect(within(modalContainer).queryByTestId('content')).toBeTruthy()
    })
    it('should not render if not opened once', () =&gt; {
github Flexget / webui / src / plugins / lists / base / RemoveListDialog.spec.tsx View on Github external
        (content, element) => content === 'button' && !!within(element).queryByText('Remove'),
      );