0.0.5 • Published 2 years ago

create-test-id v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago