This package has been deprecated

Author message:

The package is deprecated. Use the https://www.npmjs.com/package/create-locator package instead.

create-test-id
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

create-test-id

NPM version dependencies: none code style: prettier TypeScript Conventional Commits License MIT

Creates typed testId for autotests.

Install

Requires node version 16 or higher:

npm install create-test-id

Usage

In TypeScript module label.tsx with component Label:

import createTestId from 'create-test-id';
// or
import {createTestId} from 'create-test-id';

import {inputTestId} from 'components/Input';

export const labelTestId = createTestId<{input: typeof inputTestId; text: unknown}>();

labelTestId.input = inputTestId;

export const Label = () => {
  ...

  return (
    <div data-testid={labelTestId}>
      ...
      <span data-testid={labelTestId.text}>...<span>
    </div>
  );
};

In TypeScript module App.tsx with root component App:

import {labelTestId} from 'components/Label';

export const appTestId = createTestId<{label: typeof labelTestId; header: unknown}>('fooWebApp');

appTestId.label = labelTestId;

For production you can use createTestIdForProduction. This function has the same API as createTestId, but does not create new objects, and its testId is always equal to the empty string.

import {createTestId as createTestIdForDev, createTestIdForProduction} from 'create-test-id';

export const createTestId = __IS_PRODUCTION__ ? createTestIdForProduction : createTestIdForDev;

License

MIT

Package Sidebar

Install

npm i create-test-id

Weekly Downloads

2

Version

0.0.5

License

MIT

Unpacked Size

8.79 kB

Total Files

6

Last publish

Collaborators

  • uid-11222