@calm/testing-library-selector-18
TypeScript icon, indicating that this package has built-in type declarations

0.4.1 • Public • Published

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';

// define reusable selectors
const ui = {
  container: byTestId('my-container'),
  submitButton: byRole('button', { name: 'Submit' }),
  usernameInput: byLabelText('Username:'),

  // can encode more specific html element type
  passwordInput: byLabelText<HTMLInputElement>('Password:'),
};

// reuse them in the same test or across multiple tests by calling
// .get(), .getAll(), .find(), .findAll(), .query(), .queryAll()
it('example test', async () => {
  // by default elements will be queried against screen
  await ui.submitButton.find();
  expect(ui.submitButton.query()).not.toBeInDocument();
  expect(ui.submitButton.get()).toBeInDocument();

  const containers = ui.container.getAll();
  expect(containers).toHaveLength(3);

  // provide a container as first param to query element inside that container
  const username = ui.usernameInput.get(containers[0]);
});

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.4.14latest

Version History

VersionDownloads (Last 7 Days)Published
0.4.14
0.2.452
0.2.20

Package Sidebar

Install

npm i @calm/testing-library-selector-18

Weekly Downloads

56

Version

0.4.1

License

MIT

Unpacked Size

23.7 kB

Total Files

12

Last publish

Collaborators

  • alainakafkes-calm
  • rodtancalm
  • emilyz.calm
  • tyler-calm
  • tiffanyrnelson
  • giorgos.karagiorgos
  • calmrs
  • konapun.calm
  • calm-mlin
  • calmgalak
  • ryan-calm
  • patatcalm
  • kyfuhcalm
  • gustavo.calm
  • calm-jeffmay
  • eoherncalm
  • jonhummelcalm
  • kriszales
  • byamba
  • kapkaev.calm
  • ohwhen-calm
  • calmyusuf
  • kallenkortuem-calm
  • khollenbeck3
  • mholmescalm
  • sp-calm
  • matejpikovnik
  • laurabreiman
  • nat-calm
  • patricktannguyen
  • varun.ved
  • giuliacampana-calm
  • etedder-calm
  • emasjedi
  • arigonzocalm
  • rashmi.prithyani
  • calmtcat
  • shrutibidada
  • trevoradams
  • alyssadelucca
  • mbacik
  • jmartini-calm
  • sdotson2021
  • calvin.ha.calm
  • calm-kee
  • corycalm
  • raheel-calm
  • danius
  • blainemuri
  • jliebz
  • stobiewankenobi
  • kamlakasichainula
  • maya.hao.li
  • devops-calm
  • mbillz
  • samokralj
  • jessieliroff
  • vincentcr
  • lavanat
  • maria_stathopoulou
  • martinmarks
  • dave.chan
  • saiyerraguntla
  • danielleyasso
  • dchaganty
  • calm_will_larson
  • calmronak
  • hendersonlafond
  • 21echoes
  • ellen.wong
  • calcartman
  • cdombie
  • utako
  • juancalm
  • sunghospark-calm
  • john.ballon
  • johnson-jay-l
  • zoeytruong
  • bryanyan
  • andrewatcalm
  • oliviaxu
  • cameronatcalm
  • ebarajas.calm
  • chris.kyle
  • melhuang
  • jgkite-calm
  • paulminton
  • sselix144
  • calmjefflee
  • ncoleman15
  • m83nyc
  • jasso
  • achan-npm
  • george.volichenko
  • sonnygzz
  • luismnzrchelsea
  • saumitra.vaidya
  • stephen.wilson