Skip to content
Draft
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,4 @@
}
},
"packageManager": "pnpm@10.5.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
runDestroy,
} from 'internal-test-helpers';

import { Input, Textarea } from '@ember/component';
import EmberComponent, { Input, Textarea } from '@ember/component';
import { array, concat, fn, get, hash, on } from '@glimmer/runtime';
import GlimmerishComponent from '../../utils/glimmerish-component';

Expand All @@ -23,6 +23,7 @@ import { renderComponent, type RenderResult } from '../../../lib/renderer';
import { trackedObject } from '@ember/reactive/collections';
import { cached, tracked } from '@glimmer/tracking';
import Service, { service } from '@ember/service';
import { getOwner } from '@ember/owner';
import type Owner from '@ember/owner';

class RenderComponentTestCase extends AbstractStrictTestCase {
Expand Down Expand Up @@ -72,8 +73,10 @@ class RenderComponentTestCase extends AbstractStrictTestCase {

if ('expect' in options) {
assertHTML(options.expect);
} else {
} else if ('classic' in options) {
assertClassicComponentElement(options.classic);
} else {
throw new Error(`Unexpected (test)renderComponent options`);
}

this.assertStableRerender();
Expand Down Expand Up @@ -113,6 +116,87 @@ moduleFor(
}
);

moduleFor(
'Strict Mode - renderComponent (@ember/component)',
class extends RenderComponentTestCase {
[`@test Issue#20984: owner is destroyed: willDestroy calls owner's lookup`](assert: Assert) {
class FooService {
static create() {
return new FooService();
}

called = () => {
assert.step('called');
};
}

this.owner.register('service:foo-service', FooService);

class Foo extends EmberComponent {
willDestroy() {
assert.step('willDestroy');
let owner = getOwner(this) as Owner;

let service = owner.lookup('service:foo-service') as FooService;

service.called();
}
}

defComponent(`content`, { component: Foo });

this.renderComponent(Foo, { classic: { tagName: 'div', content: 'content' } });

assert.verifySteps([]);

run(() => destroy(this.owner));

assert.verifySteps(['willDestroy', 'called']);

assertHTML('');
}

[`@test Issue#20984: component is destroyed: willDestroy calls owner's lookup`](
assert: Assert
) {
class FooService {
static create() {
return new FooService();
}

called = () => {
assert.step('called');
};
}

this.owner.register('service:foo-service', FooService);

class Foo extends EmberComponent {
willDestroy() {
assert.step('willDestroy');
let owner = getOwner(this) as Owner;

let service = owner.lookup('service:foo-service') as FooService;

service.called();
}
}

defComponent(`content`, { component: Foo });

this.renderComponent(Foo, { classic: { tagName: 'div', content: 'content' } });

assert.verifySteps([]);

run(() => this.component?.destroy());

assert.verifySteps(['willDestroy', 'called']);

assertHTML('');
}
}
);

moduleFor(
'Strict Mode - renderComponent (direct)',
class extends AbstractStrictTestCase {
Expand Down