Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate testSelector() helper #134

Merged
merged 1 commit into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]')
Copy link
Member Author

@marcoow marcoow Jul 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff is actually the perfect explanation of why I think the helper was a bad idea in the first place ;)


// 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}"]`;
}