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

Fix legacy rendering tests (e.g. moduleForComponent) when used with Ember 3.13+ #677

Merged
merged 2 commits into from
Aug 30, 2019
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
18 changes: 15 additions & 3 deletions addon-test-support/@ember/test-helpers/setup-rendering-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,28 @@ export function isRenderingTestContext(context: BaseContext): context is Renderi
);
}

/**
@private
@param {Ember.ApplicationInstance} owner the current owner instance
@param {string} templateFullName the fill template name
@returns {Template} the template representing `templateFullName`
*/
function lookupTemplate(owner: Owner, templateFullName: string) {
let template = owner.lookup(templateFullName);
if (typeof template === 'function') return template(owner);
return template;
}

/**
@private
@param {Ember.ApplicationInstance} owner the current owner instance
@returns {Template} a template representing {{outlet}}
*/
function lookupOutletTemplate(owner: Owner): any {
let OutletTemplate = owner.lookup('template:-outlet');
let OutletTemplate = lookupTemplate(owner, 'template:-outlet');
if (!OutletTemplate) {
owner.register('template:-outlet', OUTLET_TEMPLATE);
OutletTemplate = owner.lookup('template:-outlet');
OutletTemplate = lookupTemplate(owner, 'template:-outlet');
}

return OutletTemplate;
Expand Down Expand Up @@ -120,7 +132,7 @@ export function render(template: TemplateFactory): Promise<void> {
name: 'index',
controller: context,
ViewClass: undefined,
template: owner.lookup(templateFullName),
template: lookupTemplate(owner, templateFullName),
outlets: {},
},
outlets: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ export default class extends TestModule {
}
}

function getOwnerFromModule(module) {
return (getOwner && getOwner(module.container)) || module.container.owner;
}

function lookupTemplateFromModule(module, templateFullName) {
var template = module.container.lookup(templateFullName);
if (typeof template === 'function') template = template(getOwnerFromModule(module));
return template;
}

export function setupComponentIntegrationTest() {
var module = this;
var context = this.context;
Expand All @@ -211,12 +221,12 @@ export function setupComponentIntegrationTest() {
var OutletView = module.container.factoryFor
? module.container.factoryFor('view:-outlet')
: module.container.lookupFactory('view:-outlet');
var OutletTemplate = module.container.lookup('template:-outlet');
var OutletTemplate = lookupTemplateFromModule(module, 'template:-outlet');
var toplevelView = (module.component = OutletView.create());
var hasOutletTemplate = !!OutletTemplate;
var outletState = {
render: {
owner: getOwner ? getOwner(module.container) : undefined,
owner: getOwnerFromModule(module),
into: undefined,
outlet: 'main',
name: 'application',
Expand Down Expand Up @@ -251,13 +261,13 @@ export function setupComponentIntegrationTest() {
var templateFullName = 'template:-undertest-' + ++templateId;
this.registry.register(templateFullName, template);
var stateToRender = {
owner: getOwner ? getOwner(module.container) : undefined,
owner: getOwnerFromModule(module),
into: undefined,
outlet: 'main',
name: 'index',
controller: module.context,
ViewClass: undefined,
template: module.container.lookup(templateFullName),
template: lookupTemplateFromModule(module, templateFullName),
outlets: {},
};

Expand Down