# @stylable/dom-test-kit

> Stylable DOM testing utilities

Latest version **6.1.1** (published 2024-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @stylable/dom-test-kit
pnpm add @stylable/dom-test-kit
yarn add @stylable/dom-test-kit
bun add @stylable/dom-test-kit
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.1.1 |
| Published | 2024-05-30 |
| First published | 2018-08-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18.12.0 |
| Dependencies | 3 |
| Unpacked size | 19.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1275 |
| Author | Wix.com |
| Maintainers | tomrav, avi.vahl, idoros, baraki, cijoe, alexswix |

## Links

- npm: https://www.npmjs.com/package/@stylable/dom-test-kit
- Repository: https://github.com/wix/stylable.git#master
- Homepage: https://github.com/wix/stylable/tree/master#readme
- Issues: https://github.com/wix/stylable/issues
- npm.io page: https://npm.io/package/@stylable/dom-test-kit

## Dependencies (3)

- [@stylable/core](https://npm.io/package/@stylable/core.md) ^6.1.1
- [@stylable/runtime](https://npm.io/package/@stylable/runtime.md) ^6.1.1
- [@tokey/css-selector-parser](https://npm.io/package/@tokey/css-selector-parser.md) ^0.6.2

## Recent versions

- 6.1.1 (latest) — 2024-05-30
- 5.19.0 (release-5.x) — 2024-03-05
- 6.0.0-rc.3 (next) — 2024-02-01
- 4.15.1 (release-4.x) — 2022-08-14
- 3.13.2 (release-3.x) — 2021-12-09
- 1.4.0 (release-1.x) — 2020-03-05
- 6.1.0 — 2024-05-21
- 6.0.2 — 2024-04-15
- 6.0.1 — 2024-03-19
- 6.0.0 — 2024-03-13
- 5.18.1 — 2024-02-12
- 5.18.0 — 2024-01-14
- 5.17.0 — 2023-12-03
- 6.0.0-rc.2 — 2023-11-08
- 6.0.0-rc.1 — 2023-11-08
- … 205 more at https://npm.io/package/@stylable/dom-test-kit/versions

## README

# @stylable/dom-test-kit

[![npm version](https://img.shields.io/npm/v/@stylable/dom-test-kit.svg)](https://www.npmjs.com/package/stylable/dom-test-kit)

`@stylable/dom-test-kit` is comprised of a single class, `StylableDOMUtil`, which exposes several DOM related testing utilities.

## Example

```css
/* my-component.st.css */
.root {}

.part {
  -st-states: loading;
}
```

```ts
/* test.ts */
import { StylableDOMUtil } from '@stylable/dom-test-kit';
import * as stylesheet from './my-component.st.css';

const domUtil = new StylableDOMUtil(stylesheet, document.body);
const partElement = domUtil.select('.part');

if (partElement) {
    domUtil.hasStyleState(partElement, 'loading');
}
```

## What does it do?

> Note: currently all of the provided utilities support only simplified Stylable selectors, consisting only of `class` and `pseudo-class` selectors.

### `constructor(style: RuntimeStylesheet, root?: Element)`

Initialize the `StylableDOMUtil` by providing a source stylesheet that would function as the base for all testing utilities. You may pass a DOM root element to serve as the default entry point for the `select` methods,

### `select(selector?: string, element?: Element): Element | null`

Select the first `element` in the DOM that matches the provided Stylable `selector`.

### `selectAll(selector?: string, element?: Element): Element[] | null`

Select all `elements` in the DOM that match the provided Stylable `selector`.

### `scopeSelector(selector?: string): string`

Transforms a Stylable `selector` to its target vanilla CSS.

### `hasStyleState(element: Element, stateName: string, param: StateValue = true): boolean`

Check whether the provided `element` has the corresponding state set. This method can also receive a third optional param to validate the state active value.

### `getStyleState(element: Element, stateName: string): string | null`

Get an `element` state value if exists, `null` if it does not.

## License

Copyright (c) 2017 Wix.com Ltd. All Rights Reserved. Use of this source code is governed by a [MIT license](./LICENSE).

---
_Source: https://npm.io/package/@stylable/dom-test-kit · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
