Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/anber/testid


https://github.com/anber/testid

e2e jest react react-testing-library

Last synced: 10 days ago
JSON representation

Awesome Lists containing this project

README

        

## Installation

```bash
npm i --save react-test-id
# or
yarn add react-test-id
```

## Configuration

By default the attribute name is `data-test-id` and the separator is `:`. The behaviour can be changed by creating new custom component and hooks.

```javascript
import { custom } from "react-test-id";

const [Role, useRole, useRoles] = custom({
attr: "data-role",
display: /\bwithRoles\b/.test(globalThis.location.search),
separator: ":",
});

export { Role, useRole, useRoles };
```

## Usage

```javascript
import React from 'react';
import { TestId, useTestId, useTestIds } from "react-test-id"; // if you use predefined configuration
import { TestId, useTestId, useTestIds } from "./custom"; // if you use your own configuration

function Title() {
const id = useTestId(":title");
return

;
}

function Actions() {
const [okId, cancelId] = useTestIds([":ok-button", ":cancel-button"]);
return (


Ok
Cancel

);
}

function Modal() {
return (

{id => (





)}

)
}
```

`Modal` component above generates next markup:
```HTML








```