simplabs/ember-test-selectors

Name: ember-test-selectors

Owner: simplabs

Description: Enabling better element selectors in Ember.js tests

Created: 2016-03-01 12:27:28.0

Updated: 2018-05-23 23:33:06.0

Pushed: 2018-05-17 10:00:01.0

Homepage: https://ember-test-selectors.com

Size: 760

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ember-test-selectors

Latest NPM release TravisCI Build Status

Enabling better element selectors in Ember.js tests

Features

More information on why that is useful are available on our blog!

ember-test-selectors

Installation
r install ember-test-selectors
Usage

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

icle>
1 data-test-post-title data-test-resource-id="{{post.id}}">{{post.title}}</h1>
>{{post.body}}</p>
ticle>

Once you've done that you can use attribute selectors to look up the elements:

n Acceptance Tests:

('[data-test-post-title]')
('[data-test-resource-id="2"]')

n Component Integration Tests:

.$('[data-test-post-title]').click()
.$('[data-test-resource-id="2"]').click()
Usage in Components

You can also use data-test-* attributes on components:

mments-list data-test-comments-for=post.id}}

These data-test-* attributes will be bound automatically and available as data attributes on the <div> wrapping the component template:

 id="ember123" data-test-comments-for="42">
-- comments -->
v>

You can also use boolean attributes, but make sure it is the first parameter as this makes use of Ember's positional params system.

valid }}
mments-list data-test-comments post=post}}

compiler error }}
mments-list post=post data-test-comments}}
Usage in Computed Properties

Instead of assigning data-test-comment-id in this example template:

ach comments as |comment|}}
comment-list-item comment=comment data-test-comment-id=comment.id}}
ach}}

you may also use computed properties on the component:

rt default Ember.Component({
mment: null,
ata-test-comment-id': Ember.computed.readOnly('comment.id'),

As with data-test-* attributes in the templates, these properties, whether computed or not, will be removed automatically in production builds.

Configuration

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

app = new EmberApp({
mber-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.

Deprecations

The testSelector helper was deprecated in v0.3.7. There's a codemod available at https://github.com/lorcan/test-selectors-codemod that can help make the necessary transformations to address the deprecation.

License

ember-test-selectors is developed by and © simplabs 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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.