Ember Test Selectors

7.1.0 · active · verified Tue Apr 21

Ember Test Selectors is an Ember.js addon designed to facilitate robust and stable UI testing by providing a convention for marking elements in templates with `data-test-*` attributes. These attributes are automatically stripped from production builds to minimize bundle size and prevent leakage of internal testing details. The current stable version is 7.1.0, released recently with a new plugin for Vite. The project maintains an active release cadence, typically aligning with Ember and Node.js LTS updates. Key differentiators include its tight integration with the Ember build pipeline to automatically remove test attributes and its widespread adoption within the Ember ecosystem for defining clear test-only hooks. It supports Ember versions 3.8 to 4.12 and Node.js 18 or above, with a separate `strip-test-selectors` package available for Embroider+Vite applications.

Common errors

Warnings

Install

Quickstart

Demonstrates how to install the addon, use `data-test-*` attributes in Ember templates, and then select those elements in an integration test.

ember install ember-test-selectors

// app/templates/components/my-component.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>

// app/tests/integration/components/my-component-test.js
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, click } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | my-component', function(hooks) {
  setupRenderingTest(hooks);

  test('it renders post title and handles like click', async function(assert) {
    this.set('post', { id: '123', title: 'Ember is great!', body: '...' });
    await render(hbs`<MyComponent @post={{this.post}} />`);

    assert.dom('[data-test-post-title]').hasText('Ember is great!');
    assert.dom('[data-test-resource-id="123"]').exists();

    await click('[data-test-like-button]');
    assert.ok(true, 'Like button was clicked'); // Replace with actual assertion
  });
});

view raw JSON →