Skip to content

Commit

Permalink
Merge pull request #43 from Turbo87/helper
Browse files Browse the repository at this point in the history
Simplify testSelector() import
  • Loading branch information
pangratz authored Jan 11, 2017
2 parents d93d364 + 8d3e779 commit f0f8c38
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,10 @@ and integration tests:
* `testSelector('post-title')`: Returns a selector `[data-test-post-title]`
* `testSelector('resource-id', '2')`: Returns a selector `[data-test-resource-id="2"]`

The test helpers can be imported from the `helpers/ember-test-selectors`
module:
The test helpers can be imported from the `ember-test-selectors` module:

```javascript
import testSelector from '<app-name>/tests/helpers/ember-test-selectors';
import testSelector from 'ember-test-selectors';
```

### Acceptance Test Usage
Expand Down
5 changes: 5 additions & 0 deletions addon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Ember from 'ember';

export default function testSelector(key, value) {
return Ember.isNone(value) ? `[data-test-${key}]` : `[data-test-${key}="${value}"]`;
}
16 changes: 10 additions & 6 deletions test-support/helpers/ember-test-selectors.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import Ember from 'ember';
import testSelector from 'ember-test-selectors';

const {
isNone
} = Ember;
let message = 'Importing testSelector() from "<appname>/tests/helpers/ember-test-selectors" is deprecated. ' +
'Please import testSelector() from "ember-test-selectors" instead.';

export default function testSelector(key, value) {
return isNone(value) ? `[data-test-${key}]` : `[data-test-${key}="${value}"]`;
}
Ember.deprecate(message, false, {
id: 'ember-test-selectors.test-selector-import',
until: '0.1.0',
url: 'https://github.com/simplabs/ember-test-selectors#test-helpers',
});

export default testSelector;
14 changes: 14 additions & 0 deletions tests/unit/test-selector-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { module, test } from 'qunit';

import testSelector from 'ember-test-selectors';

module('Unit | testSelector() from "ember-test-selectors"');

test('expands a selector name and attribute value corretly', function(assert) {
assert.equal(testSelector('selector', 'welcome-text'), '[data-test-selector="welcome-text"]');
assert.equal(testSelector('selector', 0), '[data-test-selector="0"]');
});

test('expands a selector name without attribute value corretly', function(assert) {
assert.equal(testSelector('selector'), '[data-test-selector]');
});

0 comments on commit f0f8c38

Please sign in to comment.