Skip to content

Commit 02c62b0

Browse files
Merge pull request #21095 from crazylogic03/fix/router-app-instance-clean
[CLEANUP beta] Fix missing ApplicationInstance in Router tests
2 parents 1d89e68 + a61412b commit 02c62b0

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

packages/@ember/routing/router.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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)