Détail du package

ember-test-selectors

mainmatter324.2kMIT7.1.0

Enabling better Test selectors in Ember.js applications.

ember-addon

readme

ember-test-selectors

Enabling better element selectors in Ember.js tests

[!NOTE] ember-test-selectors was written and is maintained by Mainmatter and contributors. We offer consulting, training, and team augmentation for Ember.js – check out our website 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!

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 classic addon, which supports Ember 3.28 or above.

Installation

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:

<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:

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:

<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:

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 © Mainmatter GmbH and contributors. It is released under the MIT License.

ember-test-selectors is not an official part of Ember.js and is not maintained by the Ember.js Core Team.

changelog

Changelog

Release (2025-04-09)

  • ember-test-selectors 7.1.0 (minor)
  • strip-test-selectors 0.1.0 (minor)

:rocket: Enhancement

:house: Internal

Committers: 1

v7.0.0 (2024-07-25)

:boom: Breaking Change

:rocket: Enhancement

:bug: Bug Fix

:house: Internal

Committers: 6

v6.0.0 (2021-07-05)

:boom: Breaking Change

  • #764 Remove deprecated automatic attribute binding (@Turbo87)
  • #756 Drop support for Node.js 10 (@Turbo87)
  • #757 Remove support for ember-cli-babel v5 (@Turbo87)
  • #759 Stop testing on non-LTS Ember releases before v3.24 (@Turbo87)
  • #758 Remove deprecated TransformTestSelectorParamsToHashPairs transform (@Turbo87)

:house: Internal

Committers: 1

v5.5.0 (2021-07-02)

:rocket: Enhancement

  • #751 Deprecate TransformTestSelectorParamsToHashPairs transform (@Turbo87)
  • #752 Deprecate ember-cli-babel v5.x support (@Turbo87)

:memo: Documentation

:house: Internal

Committers: 1

v5.4.0 (2021-06-24)

:rocket: Enhancement

  • #742 Fix caching warnings when running under Embroider (@rwjblue)

Committers: 1

v5.3.0 (2021-05-25)

:rocket: Enhancement

  • #720 Resolve class based transform deprecation (@chancancode)
  • #721 Add patchClassicComponent option to avoid deprecation warnings (@mydea)

Committers: 2

v5.2.0 (2021-05-14)

:rocket: Enhancement

Committers: 1

v5.1.0 (2021-05-07)

:rocket: Enhancement

  • #700 Convert class based template compilation plugin to functional style (@Turbo87)

:house: Internal

Committers: 1

v5.0.0 (2020-09-02)

This release drops support for Ember.js versions below v3.8 due to an update of ember-cli-htmlbars which did the same. Other than that, no further breaking changes are contained in the release.

:boom: Breaking Change

  • #527 Bump ember-cli-htmlbars from 4.3.1 to 5.1.2 (@marcoow)

:rocket: Enhancement

  • #587 bind-data-test-attributes: Avoid deprecated getWithDefault() call (@Turbo87)

:memo: Documentation

  • #588 Update Node.js and Ember.js support documentation (@Turbo87)

Committers: 2

v4.1.0 (2020-05-07)

:rocket: Enhancement

  • #521 Ensure test selector stripping works for inline template compilation and co-located components (@rwjblue)

Committers: 1

v4.0.0 (2020-02-17)

:boom: Breaking Change

:house: Internal

Committers: 1

v3.0.0 (2019-11-22)

:boom: Breaking Change

The main breaking changes in this major release are dropping support for older Ember.js, Ember CLI and Node.js versions. The v3.x series will have the following minimum requirements:

  • Ember.js 2.16 or above
  • Ember CLI 2.14 or above
  • Node.js 8 or above

  • #341 Adjust Ember.js support range to 2.16+ (@Turbo87)

  • #338 Use setupPreprocessorRegistry() hook to register HTMLBars AST plugin (@Turbo87)
  • #337 Drop support for Node.js 4 and 6 (@Turbo87)

:rocket: Enhancement

:bug: Bug Fix

  • #359 Revert "Use setupPreprocessorRegistry() hook to register HTMLBars AST plugin" (@Turbo87)

:memo: Documentation

:house: Internal

Committers: 3

v2.1.0 (2019-03-15)

:rocket: Enhancement

:bug: Bug Fix

:house: Internal

  • #315 tests: Check that link-to bindings work properly (@Turbo87)
  • #285 TravisCI: Remove deprecated sudo: false option (@Turbo87)

Committers: 3

v2.0.0 (2018-10-23)

:boom: Breaking Change

:rocket: Enhancement

:house: Internal

Committers: 2

v1.0.0 (2018-04-26)

:boom: Breaking Change

:house: Internal

Committers: 2

v0.3.9 (2018-04-03)

:rocket: Enhancement

:house: Internal

Committers: 2

v0.3.8 (2017-11-15)

:bug: Bug Fix

  • #155 Fix HBS transforms for Ember 1.11/1.12. (@Turbo87)
  • #150 bugfix(transform): Disable handlebars transform pre-Ember-1.13. (@pzuraq)

:memo: Documentation

  • #156 Generate CHANGELOG using lerna-changelog. (@Turbo87)
  • #141 make note about positional params. (@kellyselden)
  • #140 Added a link to the deprecations warning to point to a codemod to help address it. (@lorcan)

:house: Internal

  • #154 Skip positional params stripping tests on Ember versions without reliable support. (@Turbo87)
  • #152 add acceptance test for params-to-hash-pairs transform. (@marcoow)
  • #147 Update "yarn.lock" file and "ember-cli-babel". (@Turbo87)

Committers: 5

v0.3.7 (2017-08-04)

:rocket: Enhancement

:bug: Bug Fix

:house: Internal

Committers: 3

v0.3.6 (2017-07-11)

:rocket: Enhancement

:bug: Bug Fix

Committers: 1

v0.3.5 (2017-07-06)

:bug: Bug Fix

  • #128 Add cacheKey() methods to template transforms. (@Turbo87)

Committers: 1

v0.3.4 (2017-05-30)

:bug: Bug Fix

:house: Internal

  • #114 chore(package): update ember-cli to version 2.13.2. (@Turbo87)
  • #113 chore(package): update ember-cli-htmlbars to version 2.0.1. (@Turbo87)
  • #108 Update "ember-cli" to v2.13.0. (@Turbo87)

Committers: 1

v0.3.3 (2017-04-24)

:rocket: Enhancement

:bug: Bug Fix

:memo: Documentation

Committers: 3

v0.3.2 (2017-04-07)

:bug: Bug Fix

  • #92 Revert "Switch to treeForAddonTestSupport". (@Turbo87)

Committers: 1

v0.3.1 (2017-04-07)

:rocket: Enhancement

  • #89 Switch to treeForAddonTestSupport. (@raido)

:bug: Bug Fix

  • #88 fix: strip data-test-* attributes without explicit value from production build. (@raido)

:memo: Documentation

Committers: 2

v0.3.0 (2017-03-27)

:rocket: Enhancement

:bug: Bug Fix

:house: Internal

  • #84 update ember-cli and other libraries. (@marcoow)
  • #64 Import ESLint config from eslint-config-simplabs. (@Turbo87)

Committers: 3

v0.2.1 (2017-01-25)

:bug: Bug Fix

  • #59 attributeBindings is now frozen in debug builds on v2.11, slice it before pushing. (@bgentry)

:house: Internal

  • #63 dummy/components: Explicitly set attributeBindings to [] to test freezing. (@Turbo87)
  • #61 Upgrade to ember-cli v2.11.0. (@Turbo87)
  • #60 ember-try: Remove scenarios and rely entirely on "versionCompatibility". (@Turbo87)

Committers: 2

v0.2.0 (2017-01-23)

:rocket: Enhancement

  • #57 Add support for component data-test-* attributes without values. (@Turbo87)

:bug: Bug Fix

:house: Internal

  • #58 GreenKeeper: Ignore "babel-core" updates. (@Turbo87)

Committers: 1

v0.1.1 (2017-01-17)

:rocket: Enhancement

  • #53 Add warning when tagName is empty and data-test-* attributes are used. (@Turbo87)
  • #52 Replace initializer with IIFE in the vendor tree. (@Turbo87)

:bug: Bug Fix

  • #50 add blueprint + test helper for integration tests. (@bgentry)

Committers: 2

v0.1.0 (2017-01-12)

:rocket: Enhancement

  • #48 Updated and simplified README file. (@Turbo87)
  • #45 Add Babel 5 plugin stripping "data-test-*" properties. (@Turbo87)
  • #43 Simplify testSelector() import. (@Turbo87)
  • #27 Auto bind component data-test-* attributes. (@marcoow)
  • #42 Introduce "strip" and deprecate "environments" option. (@Turbo87)
  • #40 Strip "data-test-" attributes from component and helper invocations. (@Turbo87)
  • #37 Simplify AST walker and remove "lodash" dependency. (@Turbo87)
  • #36 Run tests with and without stripping test selectors. (@Turbo87)
  • #25 Simplify testSelector() function. (@Turbo87)

:bug: Bug Fix

:memo: Documentation

:house: Internal

Committers: 4

0.0.5 (2016-11-23)

:rocket: Enhancement

:bug: Bug Fix

Committers: 2

0.0.4 (2016-09-06)

:bug: Bug Fix

:memo: Documentation

Committers: 2

0.0.3 (2016-04-08)

:rocket: Enhancement

  • #14 Add ability to specify envs to strip selectors.. (@blimmer)

:memo: Documentation

:house: Internal

  • #16 Remove duplicate repository field in package.json. (@marcoow)

Committers: 3

0.0.2 (2016-03-21)

:rocket: Enhancement

Committers: 2

0.0.1 (2016-03-04)

:rocket: Enhancement

  • #7 Add the plugin to the registry when in production environment. (@pangratz)

:bug: Bug Fix

:memo: Documentation

:house: Internal

Committers: 2