Skip to content

Commit

Permalink
Merge pull request #12 from pdud/test-helpers
Browse files Browse the repository at this point in the history
Add test helpers
  • Loading branch information
marcoow committed Mar 21, 2016
2 parents bee6c7f + 897b6ba commit ce4f701
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,33 @@ delivered__:
</article>
```

## Testing

Ember Test Selectors comes with a test helper that can be used in acceptance & 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 in the application's namespace:

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

### Acceptance Test Usage

```javascript
find(testSelector('post-title')) // => find('[data-test-post-title]')
find(testSelector('selector', 'post-title')) // => find('[data-test-selector="post-title"]')
```

### Integration Test Usage

```javascript
this.$(testSelector('post-title')).click() // => this.$('[data-test-post-title]').click()
this.$(testSelector('selector', 'post-title')).click() // => this.$('[data-test-selector="post-title"]').click()
```

## License

ember-test-selectors is developed by and &copy;
Expand Down
9 changes: 9 additions & 0 deletions test-support/helpers/ember-test-selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function testSelector(key, value) {
let selector;
if (value) {
selector = `[data-test-${key}="${value}"]`;
} else {
selector = `[data-test-${key}]`;
}
return selector;
};
12 changes: 12 additions & 0 deletions tests/unit/test-support/helpers-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import testSelector from 'dummy/tests/helpers/ember-test-selectors';
import { module, test } from 'qunit';

module('test-support helpers');

test('testSelector with a value', function(assert) {
assert.equal(testSelector('selector', 'welcome-text'), '[data-test-selector="welcome-text"]');
});

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

0 comments on commit ce4f701

Please sign in to comment.