Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecations targeting v3.0.0 #1291

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 18 additions & 61 deletions addon-test-support/@ember/test-helpers/setup-rendering-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,26 @@ const OUTLET_TEMPLATE = hbs`{{outlet}}`;
const EMPTY_TEMPLATE = hbs``;
const INVOKE_PROVIDED_COMPONENT = hbs`<this.ProvidedComponent />`;

export interface RenderingTestContext extends TestContext {
render(template: TemplateFactory): Promise<void>;
clearRender(): Promise<void>;
const hasCalledSetupRenderingContext = Symbol();

export interface RenderingTestContext extends TestContext {
element: Element | Document;
[hasCalledSetupRenderingContext]?: true;
}

// Isolates the notion of transforming a TextContext into a RenderingTestContext.
// eslint-disable-next-line require-jsdoc
function prepare(context: TestContext): RenderingTestContext {
let renderingTestContext = context as RenderingTestContext;
(context as RenderingTestContext)[hasCalledSetupRenderingContext] = true;
return context as RenderingTestContext;
}

// eslint-disable-next-line require-jsdoc
export function isRenderingTestContext(
context: BaseContext
): context is RenderingTestContext {
return (
isTestContext(context) &&
typeof context['render'] === 'function' &&
typeof context['clearRender'] === 'function'
);
return isTestContext(context) && hasCalledSetupRenderingContext in context;
}

/**
Expand Down Expand Up @@ -293,58 +297,11 @@ export default function setupRenderingContext(
let testMetadata = getTestMetadata(context);
testMetadata.setupTypes.push('setupRenderingContext');

let renderingContext = prepare(context);

return Promise.resolve()
.then(() => {
let { owner } = context;

let renderDeprecationWrapper = function (template: TemplateFactory) {
deprecate(
'Using this.render has been deprecated, consider using `render` imported from `@ember/test-helpers`.',
false,
{
id: 'ember-test-helpers.setup-rendering-context.render',
until: '3.0.0',
for: '@ember/test-helpers',
since: {
enabled: '2.0.0',
available: '2.0.0',
},
}
);

return render(template);
};

let clearRenderDeprecationWrapper = function () {
deprecate(
'Using this.clearRender has been deprecated, consider using `clearRender` imported from `@ember/test-helpers`.',
false,
{
id: 'ember-test-helpers.setup-rendering-context.clearRender',
until: '3.0.0',
for: '@ember/test-helpers',
since: {
enabled: '2.0.0',
available: '2.0.0',
},
}
);

return clearRender();
};

Object.defineProperty(context, 'render', {
configurable: true,
enumerable: true,
value: renderDeprecationWrapper,
writable: false,
});
Object.defineProperty(context, 'clearRender', {
configurable: true,
enumerable: true,
value: clearRenderDeprecationWrapper,
writable: false,
});
let { owner } = renderingContext;

// When the host app uses `setApplication` (instead of `setResolver`) the event dispatcher has
// already been setup via `applicationInstance.boot()` in `./build-owner`. If using
Expand Down Expand Up @@ -378,13 +335,13 @@ export default function setupRenderingContext(

// initially render a simple empty template
return render(EMPTY_TEMPLATE).then(() => {
(run as Function)(toplevelView, 'appendTo', getRootElement());
run(toplevelView, 'appendTo', getRootElement());

return settled();
});
})
.then(() => {
Object.defineProperty(context, 'element', {
Object.defineProperty(renderingContext, 'element', {
configurable: true,
enumerable: true,
// ensure the element is based on the wrapping toplevel view
Expand All @@ -402,6 +359,6 @@ export default function setupRenderingContext(
writable: false,
});

return context as RenderingTestContext;
return renderingContext;
});
}
27 changes: 0 additions & 27 deletions tests/unit/setup-rendering-context-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,6 @@ module('setupRenderingContext', function (hooks) {
assert.ok(isSettled(), 'should be settled');
});

overwriteTest('render');
overwriteTest('clearRender');

test('can invoke template only components', async function (assert) {
await render(hbs`{{template-only}}`);

Expand Down Expand Up @@ -899,30 +896,6 @@ module('setupRenderingContext', function (hooks) {
});
});
}

module('this.render and this.clearRender deprecations', function () {
test('this.render() and this.clearRender deprecation message', async function (assert) {
await this.render(hbs`<button>Click me</button>`);

assert.expect(3);

assert.equal(
this.element.querySelector('button').textContent.trim(),
'Click me',
'Button is still rendered'
);

assert.deprecationsInclude(
'Using this.render has been deprecated, consider using `render` imported from `@ember/test-helpers`.'
);

await this.clearRender();

assert.deprecationsInclude(
'Using this.clearRender has been deprecated, consider using `clearRender` imported from `@ember/test-helpers`.'
);
});
});
}

module('with only application set', function (hooks) {
Expand Down