diff --git a/addon/src/setup-application-context.ts b/addon/src/setup-application-context.ts index 40f3adfca..c2cb961a0 100644 --- a/addon/src/setup-application-context.ts +++ b/addon/src/setup-application-context.ts @@ -4,12 +4,9 @@ import { isTestContext, type TestContext, } from './setup-context.ts'; -import global from './global.ts'; -import hasEmberVersion from './has-ember-version.ts'; import settled from './settled.ts'; import getTestMetadata from './test-metadata.ts'; import { runHooks } from './helper-hooks.ts'; -import type Router from '@ember/routing/router'; import type RouterService from '@ember/routing/router-service'; import { assert } from '@ember/debug'; @@ -17,9 +14,7 @@ export interface ApplicationTestContext extends TestContext { element?: Element | null; } -const CAN_USE_ROUTER_EVENTS = hasEmberVersion(3, 6); let routerTransitionsPending: boolean | null = null; -const ROUTER = new WeakMap(); const HAS_SETUP_ROUTER = new WeakMap(); // eslint-disable-next-line require-jsdoc @@ -36,33 +31,7 @@ export function isApplicationTestContext( @returns {(boolean|null)} if there are pending transitions */ export function hasPendingTransitions(): boolean | null { - if (CAN_USE_ROUTER_EVENTS) { - return routerTransitionsPending; - } - - const context = getContext(); - - // there is no current context, we cannot check - if (context === undefined) { - return null; - } - - const router = ROUTER.get(context); - - if (router === undefined) { - // if there is no router (e.g. no `visit` calls made yet), we cannot - // check for pending transitions but this is explicitly not an error - // condition - return null; - } - - const routerMicrolib = router._routerMicrolib || router.router; - - if (routerMicrolib === undefined) { - return null; - } - - return !!routerMicrolib.activeTransition; + return routerTransitionsPending; } /** @@ -88,29 +57,19 @@ export function setupRouterSettlednessTracking() { HAS_SETUP_ROUTER.set(context, true); const { owner } = context; - let router: Router | RouterService; - if (CAN_USE_ROUTER_EVENTS) { - // SAFETY: unfortunately we cannot `assert` here at present because the - // class is not exported, only the type, since it is not designed to be - // sub-classed. The most we can do at present is assert that it at least - // *exists* and assume that if it does exist, it is bound correctly. - const routerService = owner.lookup('service:router'); - assert('router service is not set up correctly', !!routerService); - router = routerService as RouterService; - - // track pending transitions via the public routeWillChange / routeDidChange APIs - // routeWillChange can fire many times and is only useful to know when we have _started_ - // transitioning, we can then use routeDidChange to signal that the transition has settled - router.on('routeWillChange', () => (routerTransitionsPending = true)); - router.on('routeDidChange', () => (routerTransitionsPending = false)); - } else { - // SAFETY: similarly, this cast cannot be made safer because on the versions - // where we fall into this path, this is *also* not an exported class. - const mainRouter = owner.lookup('router:main'); - assert('router:main is not available', !!mainRouter); - router = mainRouter as Router; - ROUTER.set(context, router); - } + + // SAFETY: unfortunately we cannot `assert` here at present because the + // class is not exported, only the type, since it is not designed to be + // sub-classed. The most we can do at present is assert that it at least + // *exists* and assume that if it does exist, it is bound correctly. + const router = owner.lookup('service:router') as RouterService; + assert('router service is not set up correctly', !!router); + + // track pending transitions via the public routeWillChange / routeDidChange APIs + // routeWillChange can fire many times and is only useful to know when we have _started_ + // transitioning, we can then use routeDidChange to signal that the transition has settled + router.on('routeWillChange', () => (routerTransitionsPending = true)); + router.on('routeDidChange', () => (routerTransitionsPending = false)); // hook into teardown to reset local settledness state const ORIGINAL_WILL_DESTROY = router.willDestroy; @@ -168,13 +127,7 @@ export function visit( return visitResult; }) .then(() => { - if (global.EmberENV._APPLICATION_TEMPLATE_WRAPPER !== false) { - context.element = document.querySelector( - '#ember-testing > .ember-view', - ); - } else { - context.element = document.querySelector('#ember-testing'); - } + context.element = document.querySelector('#ember-testing'); }) .then(settled) .then(() => { @@ -203,8 +156,6 @@ export function currentRouteName(): string { return currentRouteName; } -const HAS_CURRENT_URL_ON_ROUTER = hasEmberVersion(2, 13); - /** @public @returns {string} the applications current url @@ -218,30 +169,22 @@ export function currentURL(): string { } const router = context.owner.lookup('router:main') as any; + const routerCurrentURL = router.currentURL; + + // SAFETY: this path is a lie for the sake of the public-facing types. The + // framework itself sees this path, but users never do. A user who calls the + // API without calling `visit()` will see an `UnrecognizedURLError`, rather + // than getting back `null`. + if (routerCurrentURL === null) { + return routerCurrentURL as never as string; + } - if (HAS_CURRENT_URL_ON_ROUTER) { - const routerCurrentURL = router.currentURL; - - // SAFETY: this path is a lie for the sake of the public-facing types. The - // framework itself sees this path, but users never do. A user who calls the - // API without calling `visit()` will see an `UnrecognizedURLError`, rather - // than getting back `null`. - if (routerCurrentURL === null) { - return routerCurrentURL as never as string; - } - - assert( - `currentUrl should be a string, but was ${typeof routerCurrentURL}`, - typeof routerCurrentURL === 'string', - ); + assert( + `currentUrl should be a string, but was ${typeof routerCurrentURL}`, + typeof routerCurrentURL === 'string', + ); - return routerCurrentURL; - } else { - // SAFETY: this is *positively ancient* and should probably be removed at - // some point; old routers which don't have `currentURL` *should* have a - // `location` with `getURL()` per the docs for 2.12. - return (router.location as any).getURL(); - } + return routerCurrentURL; } /** diff --git a/addon/src/setup-rendering-context.ts b/addon/src/setup-rendering-context.ts index d2581d75d..6006a8822 100644 --- a/addon/src/setup-rendering-context.ts +++ b/addon/src/setup-rendering-context.ts @@ -1,6 +1,5 @@ import { run } from '@ember/runloop'; import Ember from 'ember'; -import global from './global.ts'; import { type BaseContext, type TestContext, @@ -13,7 +12,6 @@ import type { Owner } from './build-owner.ts'; import getTestMetadata from './test-metadata.ts'; import { assert } from '@ember/debug'; import { runHooks } from './helper-hooks.ts'; -import hasEmberVersion from './has-ember-version.ts'; import isComponent from './-internal/is-component.ts'; import { ComponentRenderMap, SetUsage } from './setup-context.ts'; @@ -188,20 +186,6 @@ export function render( }; toplevelView.setOutletState(outletState); - // Ember's rendering engine is integration with the run loop so that when a run - // loop starts, the rendering is scheduled to be done. - // - // Ember should be ensuring an instance on its own here (the act of - // setting outletState should ensureInstance, since we know we need to - // render), but on Ember < 3.23 that is not guaranteed. - if (!hasEmberVersion(3, 23)) { - // SAFETY: this was correct and type checked on the Ember v3 types, but - // since the `run` namespace does not exist in Ember v4, this no longer - // can be type checked. When (eventually) dropping support for Ember v3, - // and therefore for versions before 3.23, this can be removed entirely. - (run as any).backburner.ensureInstance(); - } - // returning settled here because the actual rendering does not happen until // the renderer detects it is dirty (which happens on backburner's end // hook), see the following implementation details: @@ -315,18 +299,7 @@ export default function setupRenderingContext( Object.defineProperty(renderingContext, 'element', { configurable: true, enumerable: true, - // ensure the element is based on the wrapping toplevel view - // Ember still wraps the main application template with a - // normal tagged view - // - // In older Ember versions (2.4) the element itself is not stable, - // and therefore we cannot update the `this.element` until after the - // rendering is completed - value: - global.EmberENV._APPLICATION_TEMPLATE_WRAPPER !== false - ? getRootElement().querySelector('.ember-view') - : getRootElement(), - + value: getRootElement(), writable: false, }); diff --git a/test-app/tests/integration/rerender-test.js b/test-app/tests/integration/rerender-test.js index b11d29a90..d1dd3844f 100644 --- a/test-app/tests/integration/rerender-test.js +++ b/test-app/tests/integration/rerender-test.js @@ -18,13 +18,8 @@ import GlimmerComponent from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; import { hbs } from 'ember-cli-htmlbars'; import { module, test } from 'qunit'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; module('rerender real-world', function (hooks) { - // this test requires Ember 3.25 in order to use lexically scoped values in templates - if (!hasEmberVersion(3, 25)) { - return; - } hooks.beforeEach(async function () { await setupContext(this); await setupRenderingContext(this); diff --git a/test-app/tests/integration/settled-test.js b/test-app/tests/integration/settled-test.js index f17bc51c4..ab9ccaef7 100644 --- a/test-app/tests/integration/settled-test.js +++ b/test-app/tests/integration/settled-test.js @@ -12,7 +12,6 @@ import { render, rerender, } from '@ember/test-helpers'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { module, test } from 'qunit'; import { hbs } from 'ember-cli-htmlbars'; import Pretender from 'pretender'; @@ -119,10 +118,6 @@ const TestComponent5 = Component.extend({ }); module('settled real-world scenarios', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - hooks.beforeEach(async function () { await setupContext(this); await setupRenderingContext(this); diff --git a/test-app/tests/integration/setup-rendering-context-test.js b/test-app/tests/integration/setup-rendering-context-test.js index ca974db91..4972ae7f3 100644 --- a/test-app/tests/integration/setup-rendering-context-test.js +++ b/test-app/tests/integration/setup-rendering-context-test.js @@ -15,7 +15,6 @@ import { } from '@ember/test-helpers'; import templateOnly from '@ember/component/template-only'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { setResolverRegistry } from '../helpers/resolver'; import { hbs } from 'ember-cli-htmlbars'; import { precompileTemplate } from '@ember/template-compilation'; @@ -149,60 +148,56 @@ module('setupRenderingContext "real world"', function (hooks) { }); module('lexical scope access', function () { - if (hasEmberVersion(3, 28)) { - test('can render components passed as locals', async function (assert) { - let add = helper(function ([first, second]) { - return first + second; - }); - - await render( - precompileTemplate('{{add 1 3}}', { - scope() { - return { add }; - }, - }) - ); - - assert.equal(this.element.textContent, '4'); + test('can render components passed as locals', async function (assert) { + let add = helper(function ([first, second]) { + return first + second; }); - } + + await render( + precompileTemplate('{{add 1 3}}', { + scope() { + return { add }; + }, + }) + ); + + assert.equal(this.element.textContent, '4'); + }); }); module('render with a component', function () { - if (hasEmberVersion(3, 25)) { - test('can render locally defined components', async function (assert) { - class MyComponent extends GlimmerComponent {} + test('can render locally defined components', async function (assert) { + class MyComponent extends GlimmerComponent {} - setComponentTemplate(hbs`my name is {{@name}}`, MyComponent); + setComponentTemplate(hbs`my name is {{@name}}`, MyComponent); - const somePerson = new (class { - @tracked name = 'Zoey'; - })(); + const somePerson = new (class { + @tracked name = 'Zoey'; + })(); - const template = precompileTemplate( - '', - { - scope() { - return { - somePerson, - MyComponent, - }; - }, - } - ); + const template = precompileTemplate( + '', + { + scope() { + return { + somePerson, + MyComponent, + }; + }, + } + ); - const component = setComponentTemplate(template, templateOnly()); + const component = setComponentTemplate(template, templateOnly()); - await render(component); + await render(component); - assert.equal(this.element.textContent, 'my name is Zoey'); + assert.equal(this.element.textContent, 'my name is Zoey'); - somePerson.name = 'Tomster'; + somePerson.name = 'Tomster'; - await rerender(); + await rerender(); - assert.equal(this.element.textContent, 'my name is Tomster'); - }); - } + assert.equal(this.element.textContent, 'my name is Tomster'); + }); }); }); diff --git a/test-app/tests/unit/dom/blur-test.js b/test-app/tests/unit/dom/blur-test.js index 83e30f8bc..140a6762b 100644 --- a/test-app/tests/unit/dom/blur-test.js +++ b/test-app/tests/unit/dom/blur-test.js @@ -8,7 +8,6 @@ import { } from '@ember/test-helpers'; import { buildInstrumentedElement, insertElement } from '../../helpers/events'; import { isEdge, isChrome } from '../../helpers/browser-detect'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { createDescriptor } from 'dom-element-descriptors'; let focusSteps = ['focus', 'focusin']; @@ -23,10 +22,6 @@ if (isChrome) { } module('DOM Helper: blur', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, elementWithFocus; hooks.beforeEach(async function (assert) { diff --git a/test-app/tests/unit/dom/click-test.js b/test-app/tests/unit/dom/click-test.js index 25591b4dc..fb0eb0c37 100644 --- a/test-app/tests/unit/dom/click-test.js +++ b/test-app/tests/unit/dom/click-test.js @@ -5,7 +5,6 @@ import { instrumentElement, insertElement, } from '../../helpers/events'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { isChrome } from '../../helpers/browser-detect'; import { registerHooks, @@ -15,10 +14,6 @@ import { import { createDescriptor } from 'dom-element-descriptors'; module('DOM Helper: click', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, element; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/dom/double-click-test.js b/test-app/tests/unit/dom/double-click-test.js index 2a817acb3..47d68bd8f 100644 --- a/test-app/tests/unit/dom/double-click-test.js +++ b/test-app/tests/unit/dom/double-click-test.js @@ -10,7 +10,6 @@ import { instrumentElement, insertElement, } from '../../helpers/events'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { registerHooks, unregisterHooks, @@ -33,10 +32,6 @@ if (isChrome) { } module('DOM Helper: doubleClick', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, element; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/dom/fill-in-test.js b/test-app/tests/unit/dom/fill-in-test.js index db5c52012..f5306ee8c 100644 --- a/test-app/tests/unit/dom/fill-in-test.js +++ b/test-app/tests/unit/dom/fill-in-test.js @@ -2,7 +2,6 @@ import { module, test } from 'qunit'; import { fillIn, setupContext, teardownContext } from '@ember/test-helpers'; import { buildInstrumentedElement, insertElement } from '../../helpers/events'; import { isFirefox, isChrome } from '../../helpers/browser-detect'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { registerHooks, unregisterHooks, @@ -17,10 +16,6 @@ if (isFirefox || isChrome) { } module('DOM Helper: fillIn', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, element; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/dom/find-all-test.js b/test-app/tests/unit/dom/find-all-test.js index 28575ba96..bb0122ec1 100644 --- a/test-app/tests/unit/dom/find-all-test.js +++ b/test-app/tests/unit/dom/find-all-test.js @@ -1,12 +1,7 @@ import { module, test } from 'qunit'; import { findAll, setupContext, teardownContext } from '@ember/test-helpers'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; module('DOM Helper: findAll', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, element1, element2; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/dom/find-test.js b/test-app/tests/unit/dom/find-test.js index b2b9abe3c..e139a5ec8 100644 --- a/test-app/tests/unit/dom/find-test.js +++ b/test-app/tests/unit/dom/find-test.js @@ -1,12 +1,7 @@ import { module, test } from 'qunit'; import { find, setupContext, teardownContext } from '@ember/test-helpers'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; module('DOM Helper: find', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, element; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/dom/focus-test.js b/test-app/tests/unit/dom/focus-test.js index 7751236e5..4012a3957 100644 --- a/test-app/tests/unit/dom/focus-test.js +++ b/test-app/tests/unit/dom/focus-test.js @@ -11,7 +11,6 @@ import { instrumentElement, } from '../../helpers/events'; import { isEdge, isChrome } from '../../helpers/browser-detect'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { createDescriptor } from 'dom-element-descriptors'; let focusSteps = ['focus', 'focusin']; @@ -26,10 +25,6 @@ if (isChrome) { } module('DOM Helper: focus', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, element; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/dom/get-root-element-test.js b/test-app/tests/unit/dom/get-root-element-test.js index 3c57ac7a0..235e394f5 100644 --- a/test-app/tests/unit/dom/get-root-element-test.js +++ b/test-app/tests/unit/dom/get-root-element-test.js @@ -4,13 +4,8 @@ import { setupContext, teardownContext, } from '@ember/test-helpers'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; module('DOM Helper: getRootElement', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/dom/logging-test.js b/test-app/tests/unit/dom/logging-test.js index cdbdcface..63186b7cf 100644 --- a/test-app/tests/unit/dom/logging-test.js +++ b/test-app/tests/unit/dom/logging-test.js @@ -6,15 +6,10 @@ import { setupRenderingContext, teardownContext, } from '@ember/test-helpers'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { elementToString } from '@ember/test-helpers/dom/-logging'; import { hbs } from 'ember-cli-htmlbars'; module('elementToString()', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - hooks.beforeEach(async function () { await setupContext(this); await setupRenderingContext(this); diff --git a/test-app/tests/unit/dom/select-files-test.js b/test-app/tests/unit/dom/select-files-test.js index 6253d6475..597141063 100644 --- a/test-app/tests/unit/dom/select-files-test.js +++ b/test-app/tests/unit/dom/select-files-test.js @@ -5,13 +5,8 @@ import { teardownContext, } from '@ember/test-helpers'; import { buildInstrumentedElement } from '../../helpers/events'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; module('DOM Helper: selectFiles', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, element; const textFile = new Blob(['Hello World'], { type: 'text/plain' }); diff --git a/test-app/tests/unit/dom/tab-test.js b/test-app/tests/unit/dom/tab-test.js index 73c7f9acc..46fdd2264 100644 --- a/test-app/tests/unit/dom/tab-test.js +++ b/test-app/tests/unit/dom/tab-test.js @@ -11,7 +11,6 @@ import { instrumentElement, } from '../../helpers/events'; import { isEdge, isChrome } from '../../helpers/browser-detect'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; let _focusSteps = ['focus', 'focusin']; let _blurSteps = isEdge ? ['focusout', 'blur'] : ['blur', 'focusout']; @@ -34,10 +33,6 @@ function moveFocus(from, to) { } module('DOM Helper: tab', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, element, elements; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/dom/tap-test.js b/test-app/tests/unit/dom/tap-test.js index b3278928e..9e4ebc3e5 100644 --- a/test-app/tests/unit/dom/tap-test.js +++ b/test-app/tests/unit/dom/tap-test.js @@ -1,7 +1,6 @@ import { module, test } from 'qunit'; import { tap, setupContext, teardownContext } from '@ember/test-helpers'; import { buildInstrumentedElement, insertElement } from '../../helpers/events'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { isChrome } from '../../helpers/browser-detect'; import { registerHooks, @@ -11,10 +10,6 @@ import { import { createDescriptor } from 'dom-element-descriptors'; module('DOM Helper: tap', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, element; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/dom/trigger-event-test.js b/test-app/tests/unit/dom/trigger-event-test.js index 50dfa1a65..2abddcb05 100644 --- a/test-app/tests/unit/dom/trigger-event-test.js +++ b/test-app/tests/unit/dom/trigger-event-test.js @@ -6,14 +6,9 @@ import { registerHook, } from '@ember/test-helpers'; import { buildInstrumentedElement, insertElement } from '../../helpers/events'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { createDescriptor } from 'dom-element-descriptors'; module('DOM Helper: triggerEvent', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, element; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/dom/trigger-key-event-test.js b/test-app/tests/unit/dom/trigger-key-event-test.js index 8217f6668..e772d9227 100644 --- a/test-app/tests/unit/dom/trigger-key-event-test.js +++ b/test-app/tests/unit/dom/trigger-key-event-test.js @@ -6,14 +6,9 @@ import { registerHook, } from '@ember/test-helpers'; import { buildInstrumentedElement, insertElement } from '../../helpers/events'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { createDescriptor } from 'dom-element-descriptors'; module('DOM Helper: triggerKeyEvent', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, element; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/dom/type-in-test.js b/test-app/tests/unit/dom/type-in-test.js index 6bb01cf89..537704c39 100644 --- a/test-app/tests/unit/dom/type-in-test.js +++ b/test-app/tests/unit/dom/type-in-test.js @@ -4,7 +4,6 @@ import { buildInstrumentedElement, insertElement } from '../../helpers/events'; import { isFirefox, isChrome } from '../../helpers/browser-detect'; import { debounce } from '@ember/runloop'; import { Promise } from 'rsvp'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { registerHooks, unregisterHooks, @@ -82,10 +81,6 @@ if (isChrome) { } module('DOM Helper: typeIn', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, element; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/dom/wait-for-test.js b/test-app/tests/unit/dom/wait-for-test.js index 0a3355a70..9733dd40a 100644 --- a/test-app/tests/unit/dom/wait-for-test.js +++ b/test-app/tests/unit/dom/wait-for-test.js @@ -1,13 +1,8 @@ import { module, test } from 'qunit'; import { waitFor, setupContext, teardownContext } from '@ember/test-helpers'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { registerDescriptorData } from 'dom-element-descriptors'; module('DOM Helper: waitFor', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - let context, rootElement; hooks.beforeEach(function () { diff --git a/test-app/tests/unit/settled-test.js b/test-app/tests/unit/settled-test.js index 498bcb0e1..e0a5928dc 100644 --- a/test-app/tests/unit/settled-test.js +++ b/test-app/tests/unit/settled-test.js @@ -2,7 +2,6 @@ import Ember from 'ember'; import { module, test } from 'qunit'; import { isSettled, getSettledState } from '@ember/test-helpers'; import { TestDebugInfo } from '@ember/test-helpers/-internal/debug-info'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { _setupAJAXHooks, _teardownAJAXHooks, @@ -16,10 +15,6 @@ import ajax from '../helpers/ajax'; const WAITER_NAME = 'custom-waiter'; module('settled', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - hooks.beforeEach(function (assert) { _setupAJAXHooks(); diff --git a/test-app/tests/unit/setup-application-context-test.js b/test-app/tests/unit/setup-application-context-test.js index 11722763f..de2c0af3a 100644 --- a/test-app/tests/unit/setup-application-context-test.js +++ b/test-app/tests/unit/setup-application-context-test.js @@ -15,7 +15,6 @@ import { registerHook, isSettled, } from '@ember/test-helpers'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { setResolverRegistry } from '../helpers/resolver'; import { hbs } from 'ember-cli-htmlbars'; @@ -30,10 +29,6 @@ Router.map(function () { }); module('setupApplicationContext', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - hooks.beforeEach(async function () { let registry = { 'router:main': Router, @@ -69,19 +64,6 @@ module('setupApplicationContext', function (hooks) { }), }; - if (!hasEmberVersion(3, 12)) { - registry = { - ...registry, - // overrides for older Ember's - 'template:application': hbs` - - {{outlet}} - `, - 'template:links-to-slow': hbs`{{#link-to "slow" class="to-slow"}}to slow{{/link-to}}`, - 'template:posts/post': hbs`
{{this.model.post_id}}
`, - }; - } - setResolverRegistry(registry); await setupContext(this); diff --git a/test-app/tests/unit/setup-context-test.js b/test-app/tests/unit/setup-context-test.js index c03b6aaff..01bfd0e56 100644 --- a/test-app/tests/unit/setup-context-test.js +++ b/test-app/tests/unit/setup-context-test.js @@ -17,7 +17,6 @@ import { } from '@ember/test-helpers'; import { getDeprecationsForContext } from '@ember/test-helpers/-internal/deprecations'; import { getWarningsForContext } from '@ember/test-helpers/-internal/warnings'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { setResolverRegistry, createCustomResolver, @@ -30,10 +29,6 @@ import Ember from 'ember'; import { deprecate, warn } from '@ember/debug'; module('setupContext', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - hooks.beforeEach(function () { setResolverRegistry({ 'service:foo': Service.extend({ isFoo: true }), @@ -74,14 +69,11 @@ module('setupContext', function (hooks) { 'function', 'has expected lookup interface' ); - - if (hasEmberVersion(2, 12)) { - assert.equal( - typeof owner.factoryFor, - 'function', - 'has expected factory interface' - ); - } + assert.equal( + typeof owner.factoryFor, + 'function', + 'has expected factory interface' + ); }); overwriteTest(context, 'owner'); diff --git a/test-app/tests/unit/setup-ember-onerror-test.js b/test-app/tests/unit/setup-ember-onerror-test.js index 8d309781a..322e88dba 100644 --- a/test-app/tests/unit/setup-ember-onerror-test.js +++ b/test-app/tests/unit/setup-ember-onerror-test.js @@ -1,6 +1,5 @@ import Ember from 'ember'; import { module, test } from 'qunit'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { setupContext, teardownContext } from '@ember/test-helpers'; import { setupOnerror, resetOnerror } from '@ember/test-helpers'; @@ -17,56 +16,54 @@ module('setupOnerror', function (hooks) { } }); - if (hasEmberVersion(2, 4)) { - module('with context set', function (hooks) { - hooks.beforeEach(async function () { - await setupContext(context); - }); + module('with context set', function (hooks) { + hooks.beforeEach(async function () { + await setupContext(context); + }); - test('Ember.onerror is undefined by default', function (assert) { - assert.expect(1); + test('Ember.onerror is undefined by default', function (assert) { + assert.expect(1); - assert.equal(Ember.onerror, undefined); - }); + assert.equal(Ember.onerror, undefined); + }); - test('Ember.onerror is setup correctly', async function (assert) { - assert.expect(2); + test('Ember.onerror is setup correctly', async function (assert) { + assert.expect(2); - let onerror = (err) => err; + let onerror = (err) => err; - assert.equal(Ember.onerror, undefined); + assert.equal(Ember.onerror, undefined); - setupOnerror(onerror); + setupOnerror(onerror); - assert.equal(Ember.onerror, onerror); - }); + assert.equal(Ember.onerror, onerror); + }); - test('Ember.onerror is reset correctly', async function (assert) { - assert.expect(3); + test('Ember.onerror is reset correctly', async function (assert) { + assert.expect(3); - let onerror = (err) => err; + let onerror = (err) => err; - assert.equal(Ember.onerror, undefined); + assert.equal(Ember.onerror, undefined); - setupOnerror(onerror); + setupOnerror(onerror); - assert.equal(Ember.onerror, onerror); + assert.equal(Ember.onerror, onerror); - resetOnerror(); + resetOnerror(); - assert.equal(Ember.onerror, undefined); - }); + assert.equal(Ember.onerror, undefined); }); + }); - test('it raises an error without context', function (assert) { - assert.throws(() => { - setupOnerror(); - }, /Must setup test context before calling setupOnerror/); - }); + test('it raises an error without context', function (assert) { + assert.throws(() => { + setupOnerror(); + }, /Must setup test context before calling setupOnerror/); + }); - test('resetOnerror does not raise an error without context', function (assert) { - resetOnerror(); - assert.ok(true, 'nothing was thrown'); - }); - } + test('resetOnerror does not raise an error without context', function (assert) { + resetOnerror(); + assert.ok(true, 'nothing was thrown'); + }); }); diff --git a/test-app/tests/unit/setup-rendering-context-test.js b/test-app/tests/unit/setup-rendering-context-test.js index cd16fb953..326264ad7 100644 --- a/test-app/tests/unit/setup-rendering-context-test.js +++ b/test-app/tests/unit/setup-rendering-context-test.js @@ -1,4 +1,3 @@ -/* globals EmberENV */ import { module, test } from 'qunit'; import Service from '@ember/service'; import Component, { setComponentTemplate } from '@ember/component'; @@ -31,7 +30,6 @@ import { getOwner } from '@ember/application'; import Engine from '@ember/engine'; import { precompileTemplate } from '@ember/template-compilation'; import templateOnly from '@ember/component/template-only'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; async function buildEngineOwner(parentOwner, registry) { parentOwner.register( @@ -137,36 +135,18 @@ module('setupRenderingContext', function (hooks) { assert.equal(this.element.textContent, 'hello!'); }); - if (EmberENV._APPLICATION_TEMPLATE_WRAPPER !== false) { - test('render exposes an `.element` property with application template wrapper', async function (assert) { - let rootElement = document.getElementById('ember-testing'); - assert.notEqual( - this.element, - rootElement, - 'this.element should not be rootElement' - ); - assert.ok( - rootElement.contains(this.element), - 'this.element is _within_ the rootElement' - ); - await render(hbs`

Hello!

`); - - assert.equal(this.element.textContent, 'Hello!'); - }); - } else { - test('render exposes an `.element` property without an application template wrapper', async function (assert) { - let rootElement = document.getElementById('ember-testing'); - assert.equal( - this.element, - rootElement, - 'this.element should _be_ rootElement' - ); + test('render exposes an `.element` property without an application template wrapper', async function (assert) { + let rootElement = document.getElementById('ember-testing'); + assert.equal( + this.element, + rootElement, + 'this.element should _be_ rootElement' + ); - await render(hbs`

Hello!

`); + await render(hbs`

Hello!

`); - assert.equal(this.element.textContent, 'Hello!'); - }); - } + assert.equal(this.element.textContent, 'Hello!'); + }); test('is settled after rendering', async function (assert) { await render(hbs`Hi!`); @@ -557,346 +537,179 @@ module('setupRenderingContext', function (hooks) { assert.equal(getOwner(this), this.owner); }); - if (hasEmberVersion(3, 25)) { - // render tests for components in 3.25+ where we can use lexical scope - module('using render with a component in Ember >= 3.25', function () { - test('works with a template-only component', async function (assert) { - const name = 'Chris'; - - const template = precompileTemplate( - '

hello my name is {{name}}

', - { - scope() { - return { - name, - }; - }, - } - ); - const component = setComponentTemplate(template, templateOnly()); - await render(component); - assert.equal( - this.element.textContent, - 'hello my name is Chris', - 'has rendered content' - ); - }); - - test('works with a glimmer component', async function (assert) { - const name = 'Chris'; - const template = precompileTemplate( - '

hello my name is {{name}} and my favorite color is {{this.favoriteColor}}

', - { - scope() { - return { - name, - }; - }, - } - ); + // render tests for components in 3.25+ where we can use lexical scope + module('using render with a component in Ember >= 3.25', function () { + test('works with a template-only component', async function (assert) { + const name = 'Chris'; - class Foo extends GlimmerComponent { - favoriteColor = 'red'; + const template = precompileTemplate( + '

hello my name is {{name}}

', + { + scope() { + return { + name, + }; + }, } + ); + const component = setComponentTemplate(template, templateOnly()); + await render(component); + assert.equal( + this.element.textContent, + 'hello my name is Chris', + 'has rendered content' + ); + }); - setComponentTemplate(template, Foo); - await render(Foo); - - assert.equal( - this.element.textContent, - 'hello my name is Chris and my favorite color is red', - 'has rendered content' - ); - }); - - test('works with a classic component', async function (assert) { - const name = 'Chris'; - const template = precompileTemplate( - '

hello my name is {{name}} and my favorite color is {{this.favoriteColor}}

', - { - scope() { - return { - name, - }; - }, - } - ); - - const Foo = Component.extend({ - favoriteColor: 'red', - }); - - setComponentTemplate(template, Foo); - await render(Foo); - - assert.equal( - this.element.textContent, - 'hello my name is Chris and my favorite color is red', - 'has rendered content' - ); - }); - - test('components passed to render do *not* have access to the test context', async function (assert) { - const template = precompileTemplate( - 'the value of foo is {{this.foo}}' - ); - - class Foo extends GlimmerComponent { - foo = 'foo'; + test('works with a glimmer component', async function (assert) { + const name = 'Chris'; + const template = precompileTemplate( + '

hello my name is {{name}} and my favorite color is {{this.favoriteColor}}

', + { + scope() { + return { + name, + }; + }, } + ); - const component = setComponentTemplate(template, Foo); - - this.foo = 'bar'; + class Foo extends GlimmerComponent { + favoriteColor = 'red'; + } - await render(component); + setComponentTemplate(template, Foo); + await render(Foo); - assert.equal(this.element.textContent, 'the value of foo is foo'); - }); - - test('setting properties on the test context *before* rendering a component throws an assertion', async function (assert) { - assert.expect(1); - const template = precompileTemplate( - 'the value of foo is {{this.foo}}' - ); + assert.equal( + this.element.textContent, + 'hello my name is Chris and my favorite color is red', + 'has rendered content' + ); + }); - class Foo extends GlimmerComponent {} - - const component = setComponentTemplate(template, Foo); - - this.set('foo', 'FOO'); - this.set('bar', 'BAR'); - this.setProperties({ - baz: 'BAZ', - baq: 'BAQ', - }); - - let error; - try { - await render(component); - } catch (err) { - error = err; - } finally { - assert.equal( - error.toString(), - `Error: Assertion Failed: You cannot call \`this.set\` or \`this.setProperties\` when passing a component to \`render\`, but they were called for the following properties: - - foo - - bar - - baz - - baq` - ); + test('works with a classic component', async function (assert) { + const name = 'Chris'; + const template = precompileTemplate( + '

hello my name is {{name}} and my favorite color is {{this.favoriteColor}}

', + { + scope() { + return { + name, + }; + }, } - }); - - test('setting properties on the test context *after* rendering a component throws an assertion', async function (assert) { - const template = precompileTemplate( - 'the value of foo is {{this.foo}}' - ); + ); - class Foo extends GlimmerComponent {} + const Foo = Component.extend({ + favoriteColor: 'red', + }); - const component = setComponentTemplate(template, Foo); + setComponentTemplate(template, Foo); + await render(Foo); - await render(component); + assert.equal( + this.element.textContent, + 'hello my name is Chris and my favorite color is red', + 'has rendered content' + ); + }); - assert.throws( - () => this.set('foo', 'FOO'), - (err) => { - return err - .toString() - .includes( - 'You cannot call `this.set` when passing a component to `render()` (the rendered component does not have access to the test context).' - ); - }, - 'errors on this.set' - ); + test('components passed to render do *not* have access to the test context', async function (assert) { + const template = precompileTemplate('the value of foo is {{this.foo}}'); - assert.throws( - () => this.setProperties({ foo: 'bar?' }), - (err) => { - return err - .toString() - .includes( - 'You cannot call `this.setProperties` when passing a component to `render()` (the rendered component does not have access to the test context)' - ); - }, - 'errors on this.setProperties' - ); - }); + class Foo extends GlimmerComponent { + foo = 'foo'; + } - test('setting properties on the test context when rendering a template does not throw an assertion', async function (assert) { - const template = precompileTemplate( - 'the value of foo is {{this.foo}}' - ); + const component = setComponentTemplate(template, Foo); - this.set('foo', 'FOO'); - this.setProperties({ - foo: 'bar?', - }); + this.foo = 'bar'; - await render(template); + await render(component); - assert.true(true, 'no assertions are thrown'); - }); + assert.equal(this.element.textContent, 'the value of foo is foo'); }); - } else if (hasEmberVersion(3, 24)) { - module('using render with a component in Ember < 3.25', function () { - test('works with a template-only component', async function (assert) { - const template = precompileTemplate( - '

this is a template-only component with no dynamic content

' - ); - const component = setComponentTemplate(template, templateOnly()); - await render(component); - assert.equal( - this.element.textContent, - 'this is a template-only component with no dynamic content', - 'has rendered content' - ); - }); - test('works with a glimmer component', async function (assert) { - const template = precompileTemplate( - '

hello my favorite color is {{this.favoriteColor}}

' - ); + test('setting properties on the test context *before* rendering a component throws an assertion', async function (assert) { + assert.expect(1); + const template = precompileTemplate('the value of foo is {{this.foo}}'); - class Foo extends GlimmerComponent { - favoriteColor = 'red'; - } + class Foo extends GlimmerComponent {} - const component = setComponentTemplate(template, Foo); + const component = setComponentTemplate(template, Foo); - await render(component); - assert.equal( - this.element.textContent, - 'hello my favorite color is red', - 'has rendered content' - ); + this.set('foo', 'FOO'); + this.set('bar', 'BAR'); + this.setProperties({ + baz: 'BAZ', + baq: 'BAQ', }); - test('works with a classic component', async function (assert) { - const template = precompileTemplate( - '

hello my favorite color is {{this.favoriteColor}}

' - ); - - const Foo = Component.extend({ - favoriteColor: 'red', - }); - - const component = setComponentTemplate(template, Foo); - + let error; + try { await render(component); - + } catch (err) { + error = err; + } finally { assert.equal( - this.element.textContent, - 'hello my favorite color is red', - 'has rendered content' - ); - }); - - test('components passed to render do *not* have access to the test context', async function (assert) { - const template = precompileTemplate( - 'the value of foo is {{this.foo}}' - ); - - class Foo extends GlimmerComponent { - foo = 'foo'; - } - - const component = setComponentTemplate(template, Foo); - - this.foo = 'bar'; - - await render(component); - - assert.equal(this.element.textContent, 'the value of foo is foo'); - }); - - test('setting properties on the test context *before* rendering a component throws an assertion', async function (assert) { - assert.expect(1); - const template = precompileTemplate( - 'the value of foo is {{this.foo}}' - ); - - class Foo extends GlimmerComponent {} - - const component = setComponentTemplate(template, Foo); - - this.set('foo', 'FOO'); - this.set('bar', 'BAR'); - this.setProperties({ - baz: 'BAZ', - baq: 'BAQ', - }); - - let error; - try { - await render(component); - } catch (err) { - error = err; - } finally { - assert.equal( - error.toString(), - `Error: Assertion Failed: You cannot call \`this.set\` or \`this.setProperties\` when passing a component to \`render\`, but they were called for the following properties: + error.toString(), + `Error: Assertion Failed: You cannot call \`this.set\` or \`this.setProperties\` when passing a component to \`render\`, but they were called for the following properties: - foo - bar - baz - baq` - ); - } - }); - - test('setting properties on the test context *after* rendering a component throws an assertion', async function (assert) { - const template = precompileTemplate( - 'the value of foo is {{this.foo}}' ); + } + }); - class Foo extends GlimmerComponent {} + test('setting properties on the test context *after* rendering a component throws an assertion', async function (assert) { + const template = precompileTemplate('the value of foo is {{this.foo}}'); - const component = setComponentTemplate(template, Foo); + class Foo extends GlimmerComponent {} - await render(component); + const component = setComponentTemplate(template, Foo); - assert.throws( - () => this.set('foo', 'FOO'), - (err) => { - return err - .toString() - .includes( - 'You cannot call `this.set` when passing a component to `render()` (the rendered component does not have access to the test context).' - ); - }, - 'errors on this.set' - ); - - assert.throws( - () => this.setProperties({ foo: 'bar?' }), - (err) => { - return err - .toString() - .includes( - 'You cannot call `this.setProperties` when passing a component to `render()` (the rendered component does not have access to the test context)' - ); - }, - 'errors on this.setProperties' - ); - }); + await render(component); - test('setting properties on the test context when rendering a template does not throw an assertion', async function (assert) { - const template = precompileTemplate( - 'the value of foo is {{this.foo}}' - ); + assert.throws( + () => this.set('foo', 'FOO'), + (err) => { + return err + .toString() + .includes( + 'You cannot call `this.set` when passing a component to `render()` (the rendered component does not have access to the test context).' + ); + }, + 'errors on this.set' + ); - this.set('foo', 'FOO'); - this.setProperties({ - foo: 'bar?', - }); + assert.throws( + () => this.setProperties({ foo: 'bar?' }), + (err) => { + return err + .toString() + .includes( + 'You cannot call `this.setProperties` when passing a component to `render()` (the rendered component does not have access to the test context)' + ); + }, + 'errors on this.setProperties' + ); + }); - await render(template); + test('setting properties on the test context when rendering a template does not throw an assertion', async function (assert) { + const template = precompileTemplate('the value of foo is {{this.foo}}'); - assert.true(true, 'no assertions are thrown'); + this.set('foo', 'FOO'); + this.setProperties({ + foo: 'bar?', }); + + await render(template); + + assert.true(true, 'no assertions are thrown'); }); - } + }); } module('with only application set', function (hooks) { diff --git a/test-app/tests/unit/teardown-context-test.js b/test-app/tests/unit/teardown-context-test.js index 986f1007f..690088cd3 100644 --- a/test-app/tests/unit/teardown-context-test.js +++ b/test-app/tests/unit/teardown-context-test.js @@ -9,7 +9,6 @@ import { isSettled, } from '@ember/test-helpers'; import { setResolverRegistry } from '../helpers/resolver'; -import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import Ember from 'ember'; import hasjQuery from '../helpers/has-jquery'; import ajax from '../helpers/ajax'; @@ -17,10 +16,6 @@ import Pretender from 'pretender'; import setupManualTestWaiter from '../helpers/manual-test-waiter'; module('teardownContext', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - setupManualTestWaiter(hooks); let context;