diff --git a/README.md b/README.md index 4ea227cb..f7ece8e1 100644 --- a/README.md +++ b/README.md @@ -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 '/tests/helpers/ember-test-selectors'; +import testSelector from 'ember-test-selectors'; ``` ### Acceptance Test Usage diff --git a/addon/index.js b/addon/index.js new file mode 100644 index 00000000..8baca257 --- /dev/null +++ b/addon/index.js @@ -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}"]`; +} diff --git a/test-support/helpers/ember-test-selectors.js b/test-support/helpers/ember-test-selectors.js index a1543fb6..e228c5cb 100644 --- a/test-support/helpers/ember-test-selectors.js +++ b/test-support/helpers/ember-test-selectors.js @@ -1,9 +1,13 @@ import Ember from 'ember'; +import testSelector from 'ember-test-selectors'; -const { - isNone -} = Ember; +let message = 'Importing testSelector() from "/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; diff --git a/tests/unit/test-selector-test.js b/tests/unit/test-selector-test.js new file mode 100644 index 00000000..28854ffb --- /dev/null +++ b/tests/unit/test-selector-test.js @@ -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]'); +});