diff --git a/addon-test-support/@ember/test-helpers/-internal/get-component-manager.ts b/addon-test-support/@ember/test-helpers/-internal/get-component-manager.ts
deleted file mode 100644
index 66da3eadd..000000000
--- a/addon-test-support/@ember/test-helpers/-internal/get-component-manager.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import Ember from 'ember';
-import {
- macroCondition,
- importSync,
- dependencySatisfies,
-} from '@embroider/macros';
-import type { InternalComponentManager } from '@glimmer/interfaces';
-
-let getComponentManager: (
- definition: object,
- owner: object
-) => InternalComponentManager | null;
-
-if (macroCondition(dependencySatisfies('ember-source', '>=3.27.0-alpha.1'))) {
- let _getComponentManager =
- //@ts-ignore
- importSync('@glimmer/manager').getInternalComponentManager;
-
- getComponentManager = (definition: object, owner: object) => {
- return _getComponentManager(definition, true);
- };
-} else if (
- macroCondition(dependencySatisfies('ember-source', '>=3.25.0-beta.1'))
-) {
- let _getComponentManager = (Ember as any).__loader.require(
- '@glimmer/manager'
- ).getInternalComponentManager;
-
- getComponentManager = (definition: object, owner: object) => {
- return _getComponentManager(definition, true);
- };
-} else {
- let _getComponentManager = (Ember as any).__loader.require(
- '@glimmer/runtime'
- ).getComponentManager;
-
- getComponentManager = (definition: object, owner: object) => {
- return _getComponentManager(owner, definition);
- };
-}
-
-export default getComponentManager;
diff --git a/addon-test-support/@ember/test-helpers/-internal/is-component.ts b/addon-test-support/@ember/test-helpers/-internal/is-component.ts
deleted file mode 100644
index eb691f269..000000000
--- a/addon-test-support/@ember/test-helpers/-internal/is-component.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { macroCondition, dependencySatisfies } from '@embroider/macros';
-
-import getComponentManager from './get-component-manager';
-
-/**
- * We should ultimately get a new API from @glimmer/runtime that provides this functionality
- * (see https://github.com/emberjs/rfcs/pull/785 for more info).
- * @private
- * @param {Object} maybeComponent The thing you think might be a component
- * @param {Object} owner Owner, we need this for old versions of getComponentManager
- * @returns {boolean} True if it's a component, false if not
- */
-function isComponent(maybeComponent: object, owner: object): boolean {
- if (macroCondition(dependencySatisfies('ember-source', '>=3.25.0-beta.1'))) {
- return !!getComponentManager(maybeComponent, owner);
- } else {
- return (
- !!getComponentManager(maybeComponent, owner) ||
- ['@ember/component', '@ember/component/template-only'].includes(
- maybeComponent.toString()
- )
- );
- }
-}
-
-export default isComponent;
diff --git a/addon-test-support/@ember/test-helpers/-internal/render-settled.ts b/addon-test-support/@ember/test-helpers/-internal/render-settled.ts
index b5a366342..329da31f4 100644
--- a/addon-test-support/@ember/test-helpers/-internal/render-settled.ts
+++ b/addon-test-support/@ember/test-helpers/-internal/render-settled.ts
@@ -1,4 +1,3 @@
-import Ember from 'ember';
import {
macroCondition,
importSync,
@@ -11,20 +10,14 @@ if (macroCondition(dependencySatisfies('ember-source', '>=4.5.0-beta.1'))) {
//@ts-ignore
renderSettled = importSync('@ember/renderer').renderSettled;
} else if (
- macroCondition(dependencySatisfies('ember-source', '>=3.27.0-alpha.1'))
+ macroCondition(dependencySatisfies('ember-source', '>=4.0.0-alpha.1'))
) {
//@ts-ignore
renderSettled = importSync('@ember/-internals/glimmer').renderSettled;
-} else if (
- macroCondition(dependencySatisfies('ember-source', '>=3.6.0-alpha.1'))
-) {
- renderSettled = (Ember as any).__loader.require(
- '@ember/-internals/glimmer'
- ).renderSettled;
} else {
- renderSettled = (Ember as any).__loader.require(
- 'ember-glimmer'
- ).renderSettled;
+ throw new Error(
+ 'Using an unsupported version of Ember (@ember/test-helpers@3.0.0+ requires Ember 4 or higher)'
+ );
}
export default renderSettled;
diff --git a/addon-test-support/@ember/test-helpers/setup-application-context.ts b/addon-test-support/@ember/test-helpers/setup-application-context.ts
index e8c41c9e8..2a45c01cc 100644
--- a/addon-test-support/@ember/test-helpers/setup-application-context.ts
+++ b/addon-test-support/@ember/test-helpers/setup-application-context.ts
@@ -6,7 +6,6 @@ import {
TestContext,
} from './setup-context';
import global from './global';
-import hasEmberVersion from './has-ember-version';
import settled from './settled';
import getTestMetadata from './test-metadata';
import { runHooks } from './-internal/helper-hooks';
@@ -18,9 +17,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
@@ -37,33 +34,7 @@ export function isApplicationTestContext(
@returns {(boolean|null)} if there are pending transitions
*/
export function hasPendingTransitions(): boolean | null {
- if (CAN_USE_ROUTER_EVENTS) {
- return routerTransitionsPending;
- }
-
- let context = getContext();
-
- // there is no current context, we cannot check
- if (context === undefined) {
- return null;
- }
-
- let 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;
- }
-
- let routerMicrolib = router._routerMicrolib || router.router;
-
- if (routerMicrolib === undefined) {
- return null;
- }
-
- return !!routerMicrolib.activeTransition;
+ return routerTransitionsPending;
}
/**
@@ -90,28 +61,20 @@ export function setupRouterSettlednessTracking() {
let { 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.
- let 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.
- let 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.
+ let 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));
// hook into teardown to reset local settledness state
let ORIGINAL_WILL_DESTROY = router.willDestroy;
@@ -204,8 +167,6 @@ export function currentRouteName(): string {
return currentRouteName;
}
-const HAS_CURRENT_URL_ON_ROUTER = hasEmberVersion(2, 13);
-
/**
@public
@returns {string} the applications current url
@@ -220,29 +181,22 @@ export function currentURL(): string {
let router = context.owner.lookup('router:main');
- if (HAS_CURRENT_URL_ON_ROUTER) {
- let routerCurrentURL = get(router, 'currentURL');
+ let routerCurrentURL = get(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;
- }
+ // 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 (get(router, 'location') as any).getURL();
- }
+ return routerCurrentURL;
}
/**
diff --git a/addon-test-support/@ember/test-helpers/setup-rendering-context.ts b/addon-test-support/@ember/test-helpers/setup-rendering-context.ts
index 728af2974..0be3197cf 100644
--- a/addon-test-support/@ember/test-helpers/setup-rendering-context.ts
+++ b/addon-test-support/@ember/test-helpers/setup-rendering-context.ts
@@ -15,12 +15,22 @@ import { Owner } from './build-owner';
import getTestMetadata from './test-metadata';
import { assert } from '@ember/debug';
import { runHooks } from './-internal/helper-hooks';
-import hasEmberVersion from './has-ember-version';
-import isComponent from './-internal/is-component';
-import { macroCondition, dependencySatisfies } from '@embroider/macros';
import { ComponentRenderMap, SetUsage } from './setup-context';
import { ensureSafeComponent } from '@embroider/util';
-import type { ComponentInstance } from '@glimmer/interfaces';
+import type {
+ ComponentInstance,
+ InternalComponentManager,
+} from '@glimmer/interfaces';
+import { importSync } from '@embroider/macros';
+
+let getInternalComponentManager: (
+ definition: object
+) => InternalComponentManager;
+
+// this would be much better as a regular `import` statement, but there really isn't any way to make typescript happy with thayar
+getInternalComponentManager =
+ //@ts-ignore
+ importSync('@glimmer/manager').getInternalComponentManager;
const OUTLET_TEMPLATE = hbs`{{outlet}}`;
const EMPTY_TEMPLATE = hbs``;
@@ -33,6 +43,19 @@ export interface RenderingTestContext extends TestContext {
[hasCalledSetupRenderingContext]?: true;
}
+/**
+ * We should ultimately get a new API from @glimmer/runtime that provides this functionality
+ * (see https://github.com/emberjs/rfcs/pull/785 for more info).
+ * @private
+ * @param {Object} maybeComponent The thing you think might be a component
+ * @returns {boolean} True if it's a component, false if not
+ */
+function isComponent(maybeComponent: object): boolean {
+ let manager = getInternalComponentManager(maybeComponent);
+
+ return !!manager;
+}
+
// Isolates the notion of transforming a TextContext into a RenderingTestContext.
// eslint-disable-next-line require-jsdoc
function prepare(context: TestContext): RenderingTestContext {
@@ -131,19 +154,31 @@ export function render(
let OutletTemplate = lookupOutletTemplate(owner);
let ownerToRenderFrom = options?.owner || owner;
- if (macroCondition(dependencySatisfies('ember-source', '<3.24.0'))) {
- // Pre 3.24, we just don't support rendering components at all, so we error
- // if we find anything that isn't a template.
- const isTemplate =
- ('__id' in templateOrComponent && '__meta' in templateOrComponent) ||
- ('id' in templateOrComponent && 'meta' in templateOrComponent);
+ if (isComponent(templateOrComponent)) {
+ // We use this to track when `render` is used with a component so that we can throw an
+ // assertion if `this.{set,setProperty} is used in the same test
+ ComponentRenderMap.set(context, true);
- if (!isTemplate) {
- throw new Error(
- `Using \`render\` with something other than a pre-compiled template is not supported until Ember 3.24 (you are on ${Ember.VERSION}).`
+ const setCalls = SetUsage.get(context);
+
+ if (setCalls !== undefined) {
+ assert(
+ `You cannot call \`this.set\` or \`this.setProperties\` when passing a component to \`render\`, but they were called for the following properties:\n${setCalls
+ .map((key) => ` - ${key}`)
+ .join('\n')}`
);
}
+ let ProvidedComponent = ensureSafeComponent(
+ templateOrComponent,
+ context
+ );
+
+ context = {
+ ProvidedComponent,
+ };
+ templateOrComponent = INVOKE_PROVIDED_COMPONENT;
+ } else {
templateId += 1;
let templateFullName = `template:-undertest-${templateId}` as const;
ownerToRenderFrom.register(templateFullName, templateOrComponent);
@@ -151,40 +186,6 @@ export function render(
ownerToRenderFrom,
templateFullName
);
- } else {
- if (isComponent(templateOrComponent, owner)) {
- // We use this to track when `render` is used with a component so that we can throw an
- // assertion if `this.{set,setProperty} is used in the same test
- ComponentRenderMap.set(context, true);
-
- const setCalls = SetUsage.get(context);
-
- if (setCalls !== undefined) {
- assert(
- `You cannot call \`this.set\` or \`this.setProperties\` when passing a component to \`render\`, but they were called for the following properties:\n${setCalls
- .map((key) => ` - ${key}`)
- .join('\n')}`
- );
- }
-
- let ProvidedComponent = ensureSafeComponent(
- templateOrComponent,
- context
- );
-
- context = {
- ProvidedComponent,
- };
- templateOrComponent = INVOKE_PROVIDED_COMPONENT;
- } else {
- templateId += 1;
- let templateFullName = `template:-undertest-${templateId}` as const;
- ownerToRenderFrom.register(templateFullName, templateOrComponent);
- templateOrComponent = lookupTemplate(
- ownerToRenderFrom,
- templateFullName
- );
- }
}
let outletState = {
@@ -216,20 +217,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:
diff --git a/tests/integration/dom/scroll-to-test.js b/tests/integration/dom/scroll-to-test.js
index e24804a1c..0383dbb5b 100644
--- a/tests/integration/dom/scroll-to-test.js
+++ b/tests/integration/dom/scroll-to-test.js
@@ -7,7 +7,6 @@ import {
setupRenderingContext,
teardownContext,
} from '@ember/test-helpers';
-import hasEmberVersion from '@ember/test-helpers/has-ember-version';
import {
buildExpectedSteps,
registerHooks,
@@ -15,10 +14,6 @@ import {
} from '../../helpers/register-hooks';
module('DOM Helper: scroll-to', function (hooks) {
- if (!hasEmberVersion(2, 4)) {
- return;
- }
-
hooks.beforeEach(async function () {
await setupContext(this);
await setupRenderingContext(this);
diff --git a/tests/integration/rerender-test.js b/tests/integration/rerender-test.js
index a7e03d13c..8d4d0ac2f 100644
--- a/tests/integration/rerender-test.js
+++ b/tests/integration/rerender-test.js
@@ -16,13 +16,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/tests/integration/settled-test.js b/tests/integration/settled-test.js
index f17bc51c4..ab9ccaef7 100644
--- a/tests/integration/settled-test.js
+++ b/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/tests/integration/setup-rendering-context-test.js b/tests/integration/setup-rendering-context-test.js
index dfc169d67..eecce659e 100644
--- a/tests/integration/setup-rendering-context-test.js
+++ b/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';
@@ -143,60 +142,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(
- '
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, - }; - }, - } - ); + 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'; - - await render(component); + class Foo extends GlimmerComponent { + favoriteColor = 'red'; + } - assert.equal(this.element.textContent, 'the value of foo is foo'); - }); + setComponentTemplate(template, Foo); + await render(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, + }; + }, } + ); + + const Foo = Component.extend({ + favoriteColor: 'red', }); - 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}}' - ); + setComponentTemplate(template, Foo); + await render(Foo); - class Foo extends GlimmerComponent {} + assert.equal( + this.element.textContent, + 'hello my name is Chris and my favorite color is red', + 'has rendered content' + ); + }); - const component = setComponentTemplate(template, Foo); + 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}}'); - await render(component); + class Foo extends GlimmerComponent { + foo = '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' - ); + const component = setComponentTemplate(template, 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' - ); - }); + this.foo = 'bar'; - 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}}' - ); + await render(component); - this.set('foo', 'FOO'); - this.setProperties({ - foo: 'bar?', - }); - - await render(template); - - 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}}' + 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` ); + } + }); - class Foo extends GlimmerComponent { - foo = 'foo'; - } - - const component = setComponentTemplate(template, Foo); - - this.foo = 'bar'; - - await render(component); + 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}}'); - assert.equal(this.element.textContent, 'the value of foo is foo'); - }); + class Foo extends GlimmerComponent {} - 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}}' - ); + const component = setComponentTemplate(template, 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: - - foo - - bar - - baz - - baq` - ); - } - }); + await render(component); - 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 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' + ); - await render(component); + 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' + ); + }); - 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('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.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' - ); + this.set('foo', 'FOO'); + this.setProperties({ + foo: 'bar?', }); - 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}}' - ); - - this.set('foo', 'FOO'); - this.setProperties({ - foo: 'bar?', - }); - - await render(template); + await render(template); - assert.true(true, 'no assertions are thrown'); - }); + assert.true(true, 'no assertions are thrown'); }); - } + }); } module('with only application set', function (hooks) { diff --git a/tests/unit/teardown-context-test.js b/tests/unit/teardown-context-test.js index fcf7a4bc1..e27e16bd6 100644 --- a/tests/unit/teardown-context-test.js +++ b/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'; @@ -18,10 +17,6 @@ import setupManualTestWaiter from '../helpers/manual-test-waiter'; import { registerDestructor } from '@ember/destroyable'; module('teardownContext', function (hooks) { - if (!hasEmberVersion(2, 4)) { - return; - } - setupManualTestWaiter(hooks); let context;