From cc1bb51c7b588fccfcf06285db010d7a05060a18 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 11 Nov 2019 21:53:28 +0100 Subject: [PATCH] tests/acceptance: Replace `moduleForAcceptance()` with `setupApplicationTest()` --- ...data-test-attributes-in-components-test.js | 137 +++++++++--------- tests/helpers/destroy-app.js | 5 - tests/helpers/module-for-acceptance.js | 21 --- tests/helpers/start-app.js | 20 --- 4 files changed, 70 insertions(+), 113 deletions(-) delete mode 100644 tests/helpers/destroy-app.js delete mode 100644 tests/helpers/module-for-acceptance.js delete mode 100644 tests/helpers/start-app.js 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 017025e8..23f007f4 100644 --- a/tests/acceptance/bind-data-test-attributes-in-components-test.js +++ b/tests/acceptance/bind-data-test-attributes-in-components-test.js @@ -1,5 +1,6 @@ -import { test, skip } from 'qunit'; -import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; +import { module, test, skip } from 'qunit'; +import { setupApplicationTest } from 'ember-qunit'; +import { visit } from '@ember/test-helpers'; import config from 'dummy/config/environment'; import { hasPositionalParams } from 'dummy/version-checks'; @@ -11,70 +12,72 @@ if (!config.stripTestSelectors) { * because initializers are only applied in acceptance tests, but not in * component integration tests. */ - moduleForAcceptance('Acceptance | Initializer | ember-test-selectors', { - beforeEach() { - visit('/bind-test'); - }, - }); - - test('it binds data-test-* attributes on components', function(assert) { - 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.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.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.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.dom('.test5 div[data-test]').doesNotExist('data-test does not exists'); - }); - - test('it leaves other data attributes untouched on components', function(assert) { - 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.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.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.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.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.dom('.test11 div[data-test-something]').exists('data-test-something exists'); - }); - - test('it binds data-test attributes on {{link-to}} components', function(assert) { - assert.dom('.test-link-to-block a').hasAttribute('data-test-foo', 'bar'); - assert.dom('.test-link-to-inline a').hasAttribute('data-test-foo', 'bar'); - }); - - test('it handles the tagless components without assert when `supportsDataTestProperties` is set', function(assert) { - assert.dom('.test12 div[data-test-with-boolean-value]').doesNotExist('data-test-with-boolean-value does not exist'); - assert.dom('.test13 div[data-test-without-value]').doesNotExist('data-test-without-value does not exist'); + module('Acceptance | Initializer | ember-test-selectors', function(hooks) { + setupApplicationTest(hooks); + + hooks.beforeEach(async function() { + await visit('/bind-test'); + }); + + test('it binds data-test-* attributes on components', function(assert) { + 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.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.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.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.dom('.test5 div[data-test]').doesNotExist('data-test does not exists'); + }); + + test('it leaves other data attributes untouched on components', function(assert) { + 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.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.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.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.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.dom('.test11 div[data-test-something]').exists('data-test-something exists'); + }); + + test('it binds data-test attributes on {{link-to}} components', function(assert) { + assert.dom('.test-link-to-block a').hasAttribute('data-test-foo', 'bar'); + assert.dom('.test-link-to-inline a').hasAttribute('data-test-foo', 'bar'); + }); + + test('it handles the tagless components without assert when `supportsDataTestProperties` is set', function(assert) { + assert.dom('.test12 div[data-test-with-boolean-value]').doesNotExist('data-test-with-boolean-value does not exist'); + assert.dom('.test13 div[data-test-without-value]').doesNotExist('data-test-without-value does not exist'); + }); }); } diff --git a/tests/helpers/destroy-app.js b/tests/helpers/destroy-app.js deleted file mode 100644 index e7f983bd..00000000 --- a/tests/helpers/destroy-app.js +++ /dev/null @@ -1,5 +0,0 @@ -import { run } from '@ember/runloop'; - -export default function destroyApp(application) { - run(application, 'destroy'); -} diff --git a/tests/helpers/module-for-acceptance.js b/tests/helpers/module-for-acceptance.js deleted file mode 100644 index 0daf9c9a..00000000 --- a/tests/helpers/module-for-acceptance.js +++ /dev/null @@ -1,21 +0,0 @@ -import { Promise } from 'rsvp'; -import { module } from 'qunit'; -import startApp from '../helpers/start-app'; -import destroyApp from '../helpers/destroy-app'; - -export default function(name, options = {}) { - module(name, { - beforeEach() { - this.application = startApp(); - - if (options.beforeEach) { - return options.beforeEach.apply(this, arguments); - } - }, - - afterEach() { - let afterEach = options.afterEach && options.afterEach.apply(this, arguments); - return Promise.resolve(afterEach).then(() => destroyApp(this.application)); - } - }); -} diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js deleted file mode 100644 index 9b41b3f8..00000000 --- a/tests/helpers/start-app.js +++ /dev/null @@ -1,20 +0,0 @@ -import { merge } from '@ember/polyfills'; -import { run } from '@ember/runloop'; -import Application from '../../app'; -import config from '../../config/environment'; - -export default function startApp(attrs) { - let application; - - let attributes = merge({}, config.APP); - attributes.autoboot = true; - attributes = merge(attributes, attrs); // use defaults, but you can override; - - run(() => { - application = Application.create(attributes); - application.setupForTesting(); - application.injectTestHelpers(); - }); - - return application; -}