Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-test-selectors

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-test-selectors

Enabling better Test selectors in Ember.js applications.

  • 0.3.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
55K
decreased by-6.79%
Maintainers
1
Weekly downloads
 
Created
Source

ember-test-selectors

Latest NPM release TravisCI Build Status

Enabling better element selectors in Ember.js tests

Features

  • Provides a testSelector() function to help you select the right elements

  • 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

  • Automatically binds properties starting with data-test- on all components for development/testing builds

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

ember-test-selectors

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>
</article>

Once you've done that you can use the testSelector() function to create a CSS/jQuery selector that looks up the right elements:

import testSelector from 'ember-test-selectors';

// in Acceptance Tests:

find(testSelector('post-title')) // => find('[data-test-post-title]')
find(testSelector('resource-id', '2')) // => find('[data-test-resource-id="2"]')

// in Component Integration Tests:

this.$(testSelector('post-title')).click() // => this.$('[data-test-post-title]').click()
this.$(testSelector('resource-id', '2')).click() // => this.$('[data-test-resource-id="2"]').click()

Usage in Components

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

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

<div id="ember123" data-test-comments-for="42">
  <!-- comments -->
</div>

Usage in Computed Properties

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

{{#each comments as |comment|}}
  {{comment-list-item comment=comment data-test-comment-id=comment.id}}
{{/each}}

you may also use computed properties on the component:

export default Ember.Component({
  comment: null,
  'data-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:

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 © 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.

Keywords

FAQs

Package last updated on 06 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc