Skip to content

Commit

Permalink
deprecate testSelector helper
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoow committed Jul 14, 2017
1 parent cc0008a commit a9713c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ Enabling better element selectors in [Ember.js](http://emberjs.com) 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

Expand Down Expand Up @@ -52,21 +50,18 @@ automatically removed from `production` builds:
</article>
```

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

```js
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"]')
find('[data-test-post-title]')
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()
this.$('[data-test-post-title]').click()
this.$('[data-test-resource-id="2"]').click()
```

### Usage in Components
Expand Down
11 changes: 10 additions & 1 deletion addon/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import Ember from 'ember';

const { isNone } = Ember;
const { isNone, deprecate } = Ember;

const message = `Using the "testSelector" helper function is deprecated as it obfuscates the selectors, making the tests harder to understand.
Please use the actual attribute selectors instead, e.g. "[data-test-my-element]" instead of "testSelector('my-element')".`;

export default function testSelector(key, value) {
deprecate(message, false, {
id: 'ember-test-selectors.test-selector-helper',
until: '0.4.0',
url: 'https://github.com/simplabs/ember-test-selectors#usage',
});

return isNone(value) ? `[data-test-${key}]` : `[data-test-${key}="${value}"]`;
}

0 comments on commit a9713c8

Please sign in to comment.