DEV: Throw error if `renderInOutlet` component has no template (#24900)

This commit is contained in:
David Taylor 2023-12-14 15:51:47 +00:00 committed by GitHub
parent 057778b710
commit f51f467030
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -31,6 +31,11 @@ export function extraConnectorComponent(outletName, klass) {
if (!hasInternalComponentManager(klass)) { if (!hasInternalComponentManager(klass)) {
throw new Error("klass is not an Ember component"); throw new Error("klass is not an Ember component");
} }
if (!getComponentTemplate(klass)) {
throw new Error(
"connector component has no associated template. Ensure the template is colocated or authored with gjs."
);
}
if (outletName.includes("/")) { if (outletName.includes("/")) {
throw new Error("invalid outlet name"); throw new Error("invalid outlet name");
} }

View File

@ -466,6 +466,22 @@ module(
await render(hbs`<PluginOutlet @name="test-name" />`); await render(hbs`<PluginOutlet @name="test-name" />`);
assert.dom(".gjs-test").hasText("Hello world from gjs"); assert.dom(".gjs-test").hasText("Hello world from gjs");
}); });
test("throws errors for invalid components", function (assert) {
assert.throws(() => {
extraConnectorComponent("test-name/blah", <template>
hello world
</template>);
}, /invalid outlet name/);
assert.throws(() => {
extraConnectorComponent("test-name", {});
}, /klass is not an Ember component/);
assert.throws(() => {
extraConnectorComponent("test-name", class extends Component {});
}, /connector component has no associated template/);
});
} }
); );