From 7a186d3a6592ba48a5e1f20e330061f48d4972a2 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Wed, 21 Mar 2018 16:02:43 +0100 Subject: [PATCH] Use `qunit-dom` assertions --- package.json | 3 +- ...data-test-attributes-in-components-test.js | 36 +++++++++---------- ...ta-test-attributes-from-components-test.js | 28 +++++++-------- ...rip-data-test-attributes-from-tags-test.js | 28 +++++++-------- yarn.lock | 7 ++++ 5 files changed, 55 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index 227a13fa..dc5ce401 100644 --- a/package.json +++ b/package.json @@ -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.*" diff --git a/tests/acceptance/bind-data-test-attributes-in-components-test.js b/tests/acceptance/bind-data-test-attributes-in-components-test.js index 07bc60bb..3d031105 100644 --- a/tests/acceptance/bind-data-test-attributes-in-components-test.js +++ b/tests/acceptance/bind-data-test-attributes-in-components-test.js @@ -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'); }); } diff --git a/tests/integration/strip-data-test-attributes-from-components-test.js b/tests/integration/strip-data-test-attributes-from-components-test.js index 786582a0..e5ec3442 100644 --- a/tests/integration/strip-data-test-attributes-from-components-test.js +++ b/tests/integration/strip-data-test-attributes-from-components-test.js @@ -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 @@ -13,63 +13,63 @@ 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 { @@ -77,7 +77,7 @@ if (config.stripTestSelectors) { 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'); }); } diff --git a/tests/integration/strip-data-test-attributes-from-tags-test.js b/tests/integration/strip-data-test-attributes-from-tags-test.js index b032ad56..793837c8 100644 --- a/tests/integration/strip-data-test-attributes-from-tags-test.js +++ b/tests/integration/strip-data-test-attributes-from-tags-test.js @@ -12,38 +12,38 @@ if (config.stripTestSelectors) { test('it strips data-test-* attributes from HTML tags', function(assert) { this.render(hbs``); - 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``); - 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``); - 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``); - 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``); - 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 { @@ -51,8 +51,8 @@ if (config.stripTestSelectors) { test('it does not strip data-test-* attributes from HTML tags', function(assert) { this.render(hbs``); - 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'); }); } diff --git a/yarn.lock b/yarn.lock index 06002607..cffced02 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"