testing-library-selector
Reusable selectors for @testing-library. Define selectors for ui elements that can be reused inside the same test or between tests. Full typescript support.
Install
npm install --save-dev testing-library-selector
yarn add -D testing-library-selector
Usage
import { byLabelText, byRole, byTestId } from './selector';
const ui = {
container: byTestId('my-container'),
submitButton: byRole('button', { name: 'Submit' }),
usernameInput: byLabelText('Username:'),
passwordInput: byLabelText<HTMLInputElement>('Password:'),
};
it('example test', async () => {
await ui.submitButton.find();
expect(ui.submitButton.query()).not.toBeInDocument();
expect(ui.submitButton.get()).toBeInDocument();
const containers = ui.container.getAll();
expect(containers).toHaveLength(3);
const username = ui.usernameInput.get(containers[0]);
});