Skip to content

Commit

Permalink
Use qunit-dom assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Mar 21, 2018
1 parent 919d1b2 commit d5c0781
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 47 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"lerna-changelog": "^0.7.0",
"loader.js": "^4.5.1",
"mocha": "^5.0.0",
"multidep": "^2.0.2"
"multidep": "^2.0.2",
"qunit-dom": "^0.5.0"
},
"engines": {
"node": "^4.5 || 6.* || >= 7.*"
Expand Down
36 changes: 18 additions & 18 deletions tests/acceptance/bind-data-test-attributes-in-components-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,53 @@ if (!config.stripTestSelectors) {
});

test('it binds data-test-* attributes on components', function(assert) {
assert.equal(find('.test1').find('div[data-test-first]').length, 1, 'data-test-first exists');
assert.equal(find('.test1').find('div[data-test-first="foobar"]').length, 1, 'data-test-first has correct value');
assert.dom('.test1 div[data-test-first]').exists('data-test-first exists');
assert.dom('.test1 div[data-test-first="foobar"]').exists('data-test-first has correct value');
});

test('it binds data-test-* attributes on components in block form', function(assert) {
assert.equal(find('.test2').find('div[data-test-first]').length, 1, 'data-test-first exists');
assert.equal(find('.test2').find('div[data-test-first="foobar"]').length, 1, 'data-test-first has correct value');
assert.dom('.test2 div[data-test-first]').exists('data-test-first exists');
assert.dom('.test2 div[data-test-first="foobar"]').exists('data-test-first has correct value');
});

test('it works with multiple data-test-* attributes on components', function(assert) {
assert.equal(find('.test3').find('div[data-test-first]').length, 1, 'data-test-first exists');
assert.equal(find('.test3').find('div[data-test-first="foobar"]').length, 1, 'data-test-first has correct value');
assert.equal(find('.test3').find('div[data-test-second]').length, 1, 'data-test-second exists');
assert.equal(find('.test3').find('div[data-test-second="second"]').length, 1, 'data-test-second has correct value');
assert.dom('.test3 div[data-test-first]').exists('data-test-first exists');
assert.dom('.test3 div[data-test-first="foobar"]').exists('data-test-first has correct value');
assert.dom('.test3 div[data-test-second]').exists('data-test-second exists');
assert.dom('.test3 div[data-test-second="second"]').exists('data-test-second has correct value');
});

test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on components', function(assert) {
assert.equal(find('.test4').find('div[data-test-first]').length, 1, 'data-test-first exists');
assert.equal(find('.test4').find('div[data-test-first="foobar"]').length, 1, 'data-test-first has correct value');
assert.equal(find('.test4').find('div[data-non-test]').length, 0, 'data-non-test does not exists');
assert.dom('.test4 div[data-test-first]').exists('data-test-first exists');
assert.dom('.test4 div[data-test-first="foobar"]').exists('data-test-first has correct value');
assert.dom('.test4 div[data-non-test]').doesNotExist('data-non-test does not exists');
});

test('it leaves data-test attribute untouched on components', function(assert) {
assert.equal(find('.test5').find('div[data-test]').length, 0, 'data-test does not exists');
assert.dom('.test5 div[data-test]').doesNotExist('data-test does not exists');
});

test('it leaves other data attributes untouched on components', function(assert) {
assert.equal(find('.test6').find('div[data-non-test]').length, 0, 'data-non-test does not exists');
assert.dom('.test6 div[data-non-test]').doesNotExist('data-non-test does not exists');
});

test('it binds data-test-* attributes with boolean values on components', function(assert) {
assert.equal(find('.test7').find('div[data-test-with-boolean-value]').length, 1, 'data-test-with-boolean-value exists');
assert.dom('.test7 div[data-test-with-boolean-value]').exists('data-test-with-boolean-value exists');
});

test('it binds data-test-* attributes without values on components', function(assert) {
assert.equal(find('.test8').find('div[data-test-without-value]').length, 1, 'data-test-without-value exists');
assert.dom('.test8 div[data-test-without-value]').exists('data-test-without-value exists');
});

test('it binds data-test-* attributes without values on block components', function(assert) {
assert.equal(find('.test9').find('div[data-test-without-value]').length, 1, 'data-test-without-value exists');
assert.dom('.test9 div[data-test-without-value]').exists('data-test-without-value exists');
});

(hasPositionalParams ? test : skip)('it leaves data-test attribute without value untouched on components', function(assert) {
assert.equal(find('.test10').find('div[data-test]').length, 0, 'data-test does not exists');
assert.dom('.test10 div[data-test]').doesNotExist('data-test does not exists');
});

test('it transforms data-test params to hash pairs on components', function(assert) {
assert.equal(find('.test11').find('div[data-test-something]').length, 1, 'data-test-something exists');
assert.dom('.test11 div[data-test-something]').exists('data-test-something exists');
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { moduleForComponent, test, skip } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

import config from 'dummy/config/environment';
import { hasReliablePositionalParams } from 'dummy/version-checks';
import { hasReliablePositionalParams, hasEmberVersion } from 'dummy/version-checks';

moduleForComponent('print-test-attributes', 'StripTestSelectorsTransform plugin', {
integration: true
Expand All @@ -13,71 +13,71 @@ if (config.stripTestSelectors) {
(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with single positional params', function(assert) {
this.render(hbs`{{print-test-attributes data-test-should-not-be}}`);

assert.equal(this.$('.data-test-positional-params').text(), 0, 'there should be no params');
assert.dom('.data-test-positional-params').hasText(hasEmberVersion(2, 10) || !hasEmberVersion(2, 3) ? '' : '0', 'there should be no params');
});

(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with positional params data-test-* as first param', function(assert) {
this.render(hbs`{{print-test-attributes data-test-should-not-be "param1"}}`);

assert.equal(this.$('.data-test-positional-params').text(), 1, 'there should be only one param');
assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param');
});

(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with multiple positional params', function(assert) {
this.render(hbs`{{print-test-attributes "param1" data-test-should-not-be}}`);

assert.equal(this.$('.data-test-positional-params').text(), 1, 'there should be only one param');
assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param');
});

(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with block and multiple positional params', function(assert) {
this.render(hbs`{{#print-test-attributes "param1" data-test-should-not-be}}{{/print-test-attributes}}`);

assert.equal(this.$('.data-test-positional-params').text(), 1, 'there should be only one param');
assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param');
});

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');
assert.dom('.data-test-first').hasText('', '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');
assert.dom('.data-test-first').hasText('', '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');
assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped');
assert.dom('.data-test-second').hasText('', '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');
assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped');
assert.dom('.data-non-test').hasText('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');
assert.dom('.data-test').hasText('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');
assert.dom('.data-non-test').hasText('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');
assert.dom('.data-test-first').hasText('foobar', 'the data-test-first attribute was not stripped');
});

}
28 changes: 14 additions & 14 deletions tests/integration/strip-data-test-attributes-from-tags-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@ if (config.stripTestSelectors) {
test('it strips data-test-* attributes from HTML tags', function(assert) {
this.render(hbs`<span data-test-id="my-id" ></span>`);

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

test('it works with multiple data-test-* attributes on HTML tags', function(assert) {
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]').length, 0, 'data-test-first is stripped');
assert.equal(this.$('span[data-test-second="second-id"]').length, 0, 'data-test-second is stripped');
assert.dom('span').exists('the span is present');
assert.dom('span[data-test-first]').doesNotExist('data-test-first is stripped');
assert.dom('span[data-test-second="second-id"]').doesNotExist('data-test-second is stripped');
});

test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on HTML tags', function(assert) {
this.render(hbs`<span data-id="my-id" data-test-id="my-test-id" ></span>`);

assert.equal(this.$('span').length, 1, 'the span is present');
assert.equal(this.$('span[data-id="my-id"]').length, 1, 'data-id is not stripped');
assert.equal(this.$('span[data-test-id="my-test-id"]').length, 0, 'data-test-id is stripped');
assert.dom('span').exists('the span is present');
assert.dom('span[data-id="my-id"]').exists('data-id is not stripped');
assert.dom('span[data-test-id="my-test-id"]').doesNotExist('data-test-id is stripped');
});

test('it leaves data-test attributes untouched on HTML tags', function(assert) {
this.render(hbs`<span data-test="my-id" ></span>`);

assert.equal(this.$('span').length, 1, 'the span is present');
assert.equal(this.$('span[data-test="my-id"]').length, 1, 'data-test-id is not stripped');
assert.dom('span').exists('the span is present');
assert.dom('span[data-test="my-id"]').exists('data-test-id is not stripped');
});

test('it leaves other data attributes untouched on HTML tags', function(assert) {
this.render(hbs`<span data-id="my-id" ></span>`);

assert.equal(this.$('span').length, 1, 'the span is present');
assert.equal(this.$('span[data-id="my-id"]').length, 1, 'data-id is not stripped');
assert.dom('span').exists('the span is present');
assert.dom('span[data-id="my-id"]').exists('data-id is not stripped');
});

} else {

test('it does not strip data-test-* attributes from HTML tags', function(assert) {
this.render(hbs`<span data-test-id="my-id" ></span>`);

assert.equal(this.$('span').length, 1, 'the span is present');
assert.equal(this.$('span[data-test-id="my-id"]').length, 1, 'data-test-id is not stripped');
assert.dom('span').exists('the span is present');
assert.dom('span[data-test-id="my-id"]').exists('data-test-id is not stripped');
});

}
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4913,6 +4913,13 @@ quick-temp@^0.1.2, quick-temp@^0.1.3, quick-temp@^0.1.5, quick-temp@^0.1.8:
rimraf "^2.5.4"
underscore.string "~3.3.4"

qunit-dom@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/qunit-dom/-/qunit-dom-0.5.0.tgz#b08db6f919656e0589ebf8bd85bc313febb454d8"
dependencies:
broccoli-funnel "^2.0.0"
broccoli-merge-trees "^2.0.0"

qunit-notifications@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/qunit-notifications/-/qunit-notifications-0.1.1.tgz#3001afc6a6a77dfbd962ccbcddde12dec5286c09"
Expand Down

0 comments on commit d5c0781

Please sign in to comment.