Skip to content

Commit

Permalink
use shorthand data attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoow committed Mar 17, 2016
1 parent c114b73 commit 9aceff6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ following template:
```

one would select the post's title with the selector
`*[data-test-selector="post-title"]`. While the selector is arguably a bit
longer this approach clearly separates the test selectors from the rest of the
markup and is resilient to change as it would simply be applied to the element
rendering the post's title, regardless of the HTML structure, CSS classes etc.
Also it allows to encode more data in the markup like e.g. the post's id:
`*[data-test-post-title]`. While the selector is arguably a bit longer this
approach clearly separates the test selectors from the rest of the markup and
is resilient to change as it would simply be applied to the element rendering
the post's title, regardless of the HTML structure, CSS classes etc. Also it
allows to encode more data in the markup like e.g. the post's id:

```hbs
<article>
<h1 data-test-selector="post-title" data-test-resource-id="{{post.id}}">{{post.title}}</h1>
<h1 data-test-post-title data-test-resource-id="{{post.id}}">{{post.title}}</h1>
<p>{{post.body}}</p>
</article>
```
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/strip-data-test-attributes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ test('it strips data-test-* attributes', function(assert) {
});

test('it works with multiple data-test-* attributes', function(assert) {
this.render(hbs`<span data-test-first="first-id" data-test-second"second-id" ></span>`);
this.render(hbs`<span data-test-first data-test-second"second-id" ></span>`);

assert.equal(this.$('span').length, 1, 'the span is present');
assert.equal(this.$('span[data-test-first="first-id"]').length, 0, 'data-test-first is stripped');
assert.equal(this.$('span[data-test-first]').length, 0, 'data-test-first is stripped');
assert.equal(this.$('span[data-test-second="second-id"]').length, 0, 'data-test-second is stripped');
});

Expand Down

0 comments on commit 9aceff6

Please sign in to comment.