Skip to content

Commit 22bc893

Browse files
committed
[CLEANUP beta] Fix missing ApplicationInstance in Router tests
1 parent 6e73896 commit 22bc893

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

packages/@ember/routing/router.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
348348
// SAFETY: this is configured in `commonSetupRegistry` in the
349349
// `@ember/application/lib` package.
350350
let DefaultRoute: any = routeOwner.factoryFor('route:basic')!.class;
351-
routeOwner.register(fullRouteName, class extends DefaultRoute {});
351+
routeOwner.register(fullRouteName, class extends DefaultRoute { });
352352
route = routeOwner.lookup(fullRouteName) as Route;
353353

354354
if (DEBUG) {
@@ -664,19 +664,14 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
664664
this._toplevelView = OutletView.create({ environment, template, application });
665665
this._toplevelView.setOutletState(root);
666666

667-
// TODO(SAFETY): At least one test runs without this set correctly. At a
668-
// later time, update the test to configure this correctly. The test ID:
669667
// `Router Service - non application test: RouterService#transitionTo with basic route`
670668
let instance = owner.lookup('-application-instance:main') as ApplicationInstance;
671-
// let instance = owner.lookup('-application-instance:main') as ApplicationInstance | undefined;
672-
// assert('[BUG] unexpectedly missing `-application-instance:main`', instance !== undefined);
673-
674-
if (instance) {
675-
// SAFETY: LOL. This is calling a deprecated API with a type that we
676-
// cannot actually confirm at a type level *is* a `ViewMixin`. Seems:
677-
// not great on multiple fronts!
678-
instance.didCreateRootView(this._toplevelView as any);
679-
}
669+
assert('[BUG] unexpectedly missing `-application-instance:main`', instance !== undefined);
670+
671+
// SAFETY: LOL. This is calling a deprecated API with a type that we
672+
// cannot actually confirm at a type level *is* a `ViewMixin`. Seems:
673+
// not great on multiple fronts!
674+
instance.didCreateRootView(this._toplevelView as any);
680675
} else {
681676
this._toplevelView.setOutletState(root);
682677
}

packages/internal-test-helpers/lib/test-cases/router-non-application.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ export default class RouterNonApplicationTestCase extends AbstractTestCase {
3434
owner.register('-view-registry:main', Object.create(null), { instantiate: false });
3535
owner.register('event_dispatcher:main', EventDispatcher);
3636

37+
// This is a bit of a hack, but we need to register an application instance
38+
// so that the router can look it up. In the future, we should probably
39+
// make this a real application instance, or at least a real engine instance.
40+
let appInstance = {
41+
didCreateRootView: (view: any) => {
42+
view.appendTo(this.element);
43+
},
44+
};
45+
owner.register('-application-instance:main', appInstance, { instantiate: false });
46+
3747
this.renderer = this.owner.lookup('renderer:-dom') as Renderer;
3848
this.element = document.querySelector('#qunit-fixture')!;
3949
this.component = null;

0 commit comments

Comments
 (0)