diff --git a/packages/@ember/-internals/routing/lib/utils.ts b/packages/@ember/-internals/routing/lib/utils.ts index a4c82de6b52..d0bbf53e105 100644 --- a/packages/@ember/-internals/routing/lib/utils.ts +++ b/packages/@ember/-internals/routing/lib/utils.ts @@ -66,8 +66,10 @@ export function stashParamNames(router: EmberRouter, routeInfos: PrivateRouteInf routeInfo['_names'] = names; - let route = routeInfo.route!; - route._stashNames(routeInfo, dynamicParent!); + let route = routeInfo.route; + if (route !== undefined) { + route._stashNames(routeInfo, dynamicParent!); + } } routeInfos['_namesStashed'] = true; diff --git a/packages/ember/tests/routing/model_loading_test.js b/packages/ember/tests/routing/model_loading_test.js index 0f71d5c5fe1..3c614a5b9bb 100644 --- a/packages/ember/tests/routing/model_loading_test.js +++ b/packages/ember/tests/routing/model_loading_test.js @@ -5,983 +5,987 @@ import { Object as EmberObject, A as emberA } from '@ember/-internals/runtime'; import { moduleFor, ApplicationTestCase, getTextOf } from 'internal-test-helpers'; import { run } from '@ember/runloop'; import { computed, set } from '@ember/-internals/metal'; +import { isDestroying } from '@glimmer/destroyable'; +import RSVP from 'rsvp'; let originalConsoleError; -moduleFor( - 'Route - model loading', - class extends ApplicationTestCase { - constructor() { - super(...arguments); - this.addTemplate('home', '

Hours

'); - this.addTemplate('camelot', '

Is a silly place

'); - this.addTemplate('homepage', '

Megatroll

{{this.name}}

'); - - this.router.map(function () { - this.route('home', { path: '/' }); - }); +class LoadingTests extends ApplicationTestCase { + constructor() { + super(...arguments); + this.addTemplate('home', '

Hours

'); + this.addTemplate('camelot', '

Is a silly place

'); + this.addTemplate('homepage', '

Megatroll

{{this.name}}

'); - originalConsoleError = console.error; - } + this.router.map(function () { + this.route('home', { path: '/' }); + }); - teardown() { - super.teardown(); - console.error = originalConsoleError; - } + originalConsoleError = console.error; + } - handleURLAborts(assert, path, deprecated) { - run(() => { - let router = this.applicationInstance.lookup('router:main'); - let result; + teardown() { + super.teardown(); + console.error = originalConsoleError; + } - if (deprecated !== undefined) { - expectDeprecation(() => { - result = router.handleURL(path); - }); - } else { + handleURLAborts(assert, path, deprecated) { + run(() => { + let router = this.applicationInstance.lookup('router:main'); + let result; + + if (deprecated !== undefined) { + expectDeprecation(() => { result = router.handleURL(path); - } + }); + } else { + result = router.handleURL(path); + } - result.then( - function () { - assert.ok(false, 'url: `' + path + '` was NOT to be handled'); - }, - function (reason) { - assert.ok( - reason && reason.message === 'TransitionAborted', - 'url: `' + path + '` was to be aborted' - ); - } - ); - }); - } + result.then( + function () { + assert.ok(false, 'url: `' + path + '` was NOT to be handled'); + }, + function (reason) { + assert.ok( + reason && reason.message === 'TransitionAborted', + 'url: `' + path + '` was to be aborted' + ); + } + ); + }); + } - get currentPath() { - let currentPath; - expectDeprecation(() => { - currentPath = this.applicationInstance.lookup('controller:application').get('currentPath'); - }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); - return currentPath; - } + get currentPath() { + let currentPath; + expectDeprecation(() => { + currentPath = this.applicationInstance.lookup('controller:application').get('currentPath'); + }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); + return currentPath; + } - async ['@test warn on URLs not included in the route set'](assert) { - await this.visit('/'); + async ['@test warn on URLs not included in the route set'](assert) { + await this.visit('/'); - await assert.rejects(this.visit('/what-is-this-i-dont-even'), /\/what-is-this-i-dont-even/); - } + await assert.rejects(this.visit('/what-is-this-i-dont-even'), /\/what-is-this-i-dont-even/); + } - ['@test properties that autotrack the model update when the model changes'](assert) { - assert.expect(2); + ['@test properties that autotrack the model update when the model changes'](assert) { + assert.expect(2); - this.router.map(function () { - this.route('track', { path: '/track/:id' }); - }); + this.router.map(function () { + this.route('track', { path: '/track/:id' }); + }); - class HomeRoute extends Route { - async model({ id }) { - return { value: id }; - } + class HomeRoute extends Route { + async model({ id }) { + return { value: id }; } + } - class HomeController extends Controller { - get derivedProperty() { - return this.model.value || 'value is unset'; - } + class HomeController extends Controller { + get derivedProperty() { + return this.model.value || 'value is unset'; } + } - this.add('route:track', HomeRoute); - this.add('controller:track', HomeController); - this.addTemplate('track', '

{{this.derivedProperty}}

'); + this.add('route:track', HomeRoute); + this.add('controller:track', HomeController); + this.addTemplate('track', '

{{this.derivedProperty}}

'); - return this.visit('/track/2') - .then(() => { + return this.visit('/track/2') + .then(() => { + assert.equal( + document.querySelector('h3').innerText, + '2', + 'the derived property matches the id' + ); + }) + .then(() => { + return this.visit('/track/3').then(() => { assert.equal( document.querySelector('h3').innerText, - '2', + '3', 'the derived property matches the id' ); - }) - .then(() => { - return this.visit('/track/3').then(() => { - assert.equal( - document.querySelector('h3').innerText, - '3', - 'the derived property matches the id' - ); - }); }); - } + }); + } - ['@test The Homepage with a `setupController` hook'](assert) { - this.addTemplate( - 'home', - `