react-jest-test-utils

A collection of useful functions for writing React tests with Jest.

Usage no npm install needed!

<script type="module">
  import reactJestTestUtils from 'https://cdn.skypack.dev/react-jest-test-utils';
</script>

README

Generate Get Element by Data Attribute

npm version

This package aims to prevent you from having to write same function over and over again.

Instead of writing

document.querySelector("[data-testid=my-first-button");
document.querySelector("[data-testid=my-second-button");
document.querySelector("[data-testid=my-third-button");

each time you would like to access an element from a testid, this package allow you to write

import { generateGetElementByDataAttribute } from "generate-get-element-by-data-attribute";

const getElementByTestId = generateGetElementByDataAttribute("testid");

getElementByTestId(document.body, "first-button");
getElementByTestId(document.body, "second-button");
getElementByTestId(document.body, "third-button");

Helpful for writing a lot of Jest tests.

Type definitons are provided!