Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] assert transitions on destroyed app instances #16386

Merged
merged 2 commits into from
Mar 22, 2018
Merged
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
8 changes: 5 additions & 3 deletions packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ const EmberRouter = EmberObject.extend(Evented, {

if (DEBUG) {
if (get(this, 'namespace').LOG_TRANSITIONS) {
// eslint-disable-next-line no-console
// eslint-disable-next-line no-console
console.log(`Transitioned into '${EmberRouter._routePath(infos)}'`);
}
}
Expand Down Expand Up @@ -336,7 +336,7 @@ const EmberRouter = EmberObject.extend(Evented, {

if (DEBUG) {
if (get(this, 'namespace').LOG_TRANSITIONS) {
// eslint-disable-next-line no-console
// eslint-disable-next-line no-console
console.log(`Preparing to transition from '${EmberRouter._routePath(oldInfos)}' to '${EmberRouter._routePath(newInfos)}'`);
}
}
Expand Down Expand Up @@ -373,9 +373,11 @@ const EmberRouter = EmberObject.extend(Evented, {
*/
transitionTo(...args) {
if (resemblesURL(args[0])) {
assert(`A transition was attempted from '${this.currentRouteName}' to '${args[0]}' but the application instance has already been destroyed.`, !this.isDestroying && !this.isDestroyed);
return this._doURLTransition('transitionTo', args[0]);
}
let { routeName, models, queryParams } = extractRouteArgs(args);
assert(`A transition was attempted from '${this.currentRouteName}' to '${routeName}' but the application instance has already been destroyed.`, !this.isDestroying && !this.isDestroyed);
return this._doTransition(routeName, models, queryParams);
},

Expand All @@ -387,7 +389,7 @@ const EmberRouter = EmberObject.extend(Evented, {
if (DEBUG) {
let infos = this._routerMicrolib.currentHandlerInfos;
if (get(this, 'namespace').LOG_TRANSITIONS) {
// eslint-disable-next-line no-console
// eslint-disable-next-line no-console
console.log(`Intermediate-transitioned into '${EmberRouter._routePath(infos)}'`);
}
}
Expand Down
17 changes: 16 additions & 1 deletion packages/ember-routing/tests/system/router_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,20 @@ moduleFor('Ember Router', class extends AbstractTestCase {

triggerEvent(handlerInfos, false, ['loading']);
}
});

['@test transitionTo should throw an error when called after owner is destroyed']() {
let router = createRouter();

runDestroy(router);

router.currentRouteName = 'route-a';

expectAssertion(function() {
router.transitionTo('route-b');
}, "A transition was attempted from 'route-a' to 'route-b' but the application instance has already been destroyed.");

expectAssertion(function() {
router.transitionTo('./route-b/1');
}, "A transition was attempted from 'route-a' to './route-b/1' but the application instance has already been destroyed.");
}
});