# ember-test-selectors

> Enabling better Test selectors in Ember.js applications.

Latest version **7.1.0** (published 2025-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-test-selectors
pnpm add ember-test-selectors
yarn add ember-test-selectors
bun add ember-test-selectors
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities; has provenance; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 7.1.0 |
| Published | 2025-04-09 |
| First published | 2016-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 18.* \|\| 20.* \|\| >= 22.* |
| Dependencies | 4 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 262 |
| Author | Mainmatter GmbH |
| Maintainers | turbo87, mainmatter |
| Keywords | ember-addon |

## Links

- npm: https://www.npmjs.com/package/ember-test-selectors
- Repository: https://github.com/mainmatter/ember-test-selectors
- Homepage: https://github.com/mainmatter/ember-test-selectors#readme
- Issues: https://github.com/mainmatter/ember-test-selectors/issues
- npm.io page: https://npm.io/package/ember-test-selectors

## Dependencies (4)

- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^7.26.4
- [strip-test-selectors](https://npm.io/package/strip-test-selectors.md) 0.1.0
- [ember-cli-version-checker](https://npm.io/package/ember-cli-version-checker.md) ^5.1.2
- [calculate-cache-key-for-tree](https://npm.io/package/calculate-cache-key-for-tree.md) ^2.0.0

## Recent versions

- 7.1.0 (latest) — 2025-04-09
- 3.0.0-beta.2 (beta) — 2019-04-18
- 7.0.0 — 2024-07-25
- 6.0.0 — 2021-07-05
- 5.5.0 — 2021-07-02
- 5.4.0 — 2021-06-24
- 5.3.0 — 2021-05-25
- 5.2.0 — 2021-05-14
- 5.1.0 — 2021-05-07
- 5.0.0 — 2020-09-02
- 4.1.0 — 2020-05-07
- 4.0.0 — 2020-02-17
- 3.0.0 — 2019-11-22
- 3.0.0-beta.1 — 2019-03-16
- 2.1.0 — 2019-03-15
- … 21 more at https://npm.io/package/ember-test-selectors/versions

## README

ember-test-selectors
==============================================================================

Enabling better element selectors in [Ember.js](http://emberjs.com) tests

> [!NOTE]
> ember-test-selectors was written and is maintained by [Mainmatter](https://mainmatter.com) and contributors.
> We offer consulting, training, and team augmentation for Ember.js – check out our [website](https://mainmatter.com/ember-consulting/) to learn more!

Features
------------------------------------------------------------------------------

- Removes attributes starting with `data-test-` from HTML tags and
  component/helper invocations in your templates for production builds

- Removes properties starting with `data-test-` from your JS objects like
  component classes for production builds

More information on why that is useful are available on our
[blog](http://mainmatter.com/blog/2016/03/04/ember-test-selectors.html)!


Compatibility
------------------------------------------------------------------------------

- Ember 3.8 to Ember 4.12
- Ember CLI 3.8 or above
- Node.js 18 or above

If your Ember app is an Embroider+Vite app, you can use [strip-test-selectors](https://github.com/mainmatter/ember-test-selectors/blob/master/strip-test-selectors/README.md) classic addon, which supports Ember 3.28 or above.


Installation
------------------------------------------------------------------------------

```bash
ember install ember-test-selectors
```


Usage
------------------------------------------------------------------------------

In your templates you are now able to use `data-test-*` attributes, which are
automatically removed from `production` builds:

```hbs
<article>
  <h1 data-test-post-title data-test-resource-id={{post.id}}>{{post.title}}</h1>
  <p>{{post.body}}</p>
  <button data-test-like-button>Like</button>
</article>
```

Once you've done that you can use attribute selectors to look up and interact
with those elements:

```js
assert.dom('[data-test-post-title]').hasText('Ember is great!');

await click('[data-test-like-button]');
```

### Usage with Components

You can use the same syntax also for component invocations:

```hbs
<Spinner @color="blue" data-test-spinner>
```

Inside the `Spinner` component template the `data-test-spinner` attribute will
be applied to the element that has `...attributes` on it, or on the component
wrapper `div` element if you don't use `tagName = ''`.


### Usage in Ember addons

If you want to use ember-test-selectors in an addon make sure that it appears
in the `dependencies` section of the `package.json` file, not in the
`devDependencies`. This ensures that the selectors are also stripped correctly
even if the app that uses the addon does not use ember-test-selectors itself.


Configuration
------------------------------------------------------------------------------

You can override when the `data-test-*` attributes should be stripped from the
build by modifying your `ember-cli-build.js` file:

```js
var app = new EmberApp({
  'ember-test-selectors': {
    strip: false
  }
});
```

`strip` accepts a `Boolean` value and defaults to `!app.tests`, which means
that the attributes will be stripped for production builds, unless the build
was triggered by `ember test`. That means that if you use
`ember test --environment=production` the test selectors will still work, but
for `ember build -prod` they will be stripped out.


License
------------------------------------------------------------------------------

ember-test-selectors is developed by and &copy;
[Mainmatter GmbH](http://mainmatter.com) and contributors. It is released under the
[MIT License](https://github.com/mainmatter/ember-test-selectors/blob/master/LICENSE).

ember-test-selectors is not an official part of [Ember.js](http://emberjs.com)
and is not maintained by the Ember.js Core Team.

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