-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strip "data-test-" attributes from component and helper invocations (#40
) * tests/integration: Renamed tests to better express intention These tests are only used to check the stripping on HTML tags, not components. * dummy: Rename "data-test" component to "data-test-component" This conflicts with using a `{{data-test}}` property inside a component template * Strip "data-test-" attributes from component and helper invocations * dummy/components/print-test-attributes: Adjusted CSS selector names
- Loading branch information
Showing
5 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 4 additions & 0 deletions
4
tests/dummy/app/templates/components/print-test-attributes.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="data-test-first">{{data-test-first}}</div> | ||
<div class="data-test-second">{{data-test-second}}</div> | ||
<div class="data-non-test">{{data-non-test}}</div> | ||
<div class="data-test">{{data-test}}</div> |
58 changes: 58 additions & 0 deletions
58
tests/integration/strip-data-test-attributes-from-components-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { moduleForComponent, test } from "ember-qunit"; | ||
import hbs from "htmlbars-inline-precompile"; | ||
|
||
import config from 'dummy/config/environment'; | ||
|
||
moduleForComponent('print-test-attributes', 'StripTestSelectorsTransform plugin', { | ||
integration: true | ||
}); | ||
|
||
if (config.stripTestSelectors) { | ||
|
||
test('it strips data-test-* attributes from components', function (assert) { | ||
this.render(hbs`{{print-test-attributes data-test-first="foobar"}}`); | ||
|
||
assert.equal(this.$('.data-test-first').text(), '', 'the data-test-first was stripped'); | ||
}); | ||
|
||
test('it strips data-test-* attributes from components in block form', function (assert) { | ||
this.render(hbs`{{#print-test-attributes data-test-first="foobar"}}hello{{/print-test-attributes}}`); | ||
|
||
assert.equal(this.$('.data-test-first').text(), '', 'the data-test-first was stripped'); | ||
}); | ||
|
||
test('it works with multiple data-test-* attributes on components', function (assert) { | ||
this.render(hbs`{{print-test-attributes data-test-first="foobar" data-test-second="second"}}`); | ||
|
||
assert.equal(this.$('.data-test-first').text(), '', 'the data-test-first was stripped'); | ||
assert.equal(this.$('.data-test-second').text(), '', 'the data-test-second attribute was stripped'); | ||
}); | ||
|
||
test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on components', function (assert) { | ||
this.render(hbs`{{print-test-attributes data-test-first="foobar" data-non-test="baz"}}`); | ||
|
||
assert.equal(this.$('.data-test-first').text(), '', 'the data-test-first was stripped'); | ||
assert.equal(this.$('.data-non-test').text(), 'baz', 'the data-non-test attribute was not stripped'); | ||
}); | ||
|
||
test('it leaves data-test attributes untouched on components', function (assert) { | ||
this.render(hbs`{{print-test-attributes data-test="foo"}}`); | ||
|
||
assert.equal(this.$('.data-test').text(), 'foo', 'the data-test attribute was stripped'); | ||
}); | ||
|
||
test('it leaves other data attributes untouched on components', function (assert) { | ||
this.render(hbs`{{print-test-attributes data-non-test="foo"}}`); | ||
|
||
assert.equal(this.$('.data-non-test').text(), 'foo', 'the data-non-test attribute was not stripped'); | ||
}); | ||
|
||
} else { | ||
|
||
test('it does not strip data-test-* attributes from components', function (assert) { | ||
this.render(hbs`{{print-test-attributes data-test-first="foobar"}}`); | ||
|
||
assert.equal(this.$('.data-test-first').text(), 'foobar', 'the data-test-first attribute was not stripped'); | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters