Skip to content

Commit

Permalink
Add more route error action scenario tests.
Browse files Browse the repository at this point in the history
(cherry picked from commit ff4d431)
  • Loading branch information
rwjblue committed Dec 27, 2015
1 parent f033b1b commit 2356dd6
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions packages/ember/tests/routing/substates_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,104 @@ QUnit.test('Handled errors that re-throw aren\'t swallowed', function() {
}, function(err) { return err.msg === 'did it broke?'; });
});

QUnit.test('Handled errors that bubble can be handled at a higher level', function() {
expect(4);

var handledError;

templates['grandma'] = 'GRANDMA {{outlet}}';

Router.map(function() {
this.route('grandma', function() {
this.route('mom', { resetNamespace: true }, function() {
this.route('sally');
});
});
});

App.ApplicationController = Ember.Controller.extend();

App.MomRoute = Ember.Route.extend({
actions: {
error(err) {
step(3, 'MomRoute#error');

equal(err, handledError, 'error handled and rebubbled is handleable at heigher route');
}
}
});

App.MomSallyRoute = Ember.Route.extend({
model() {
step(1, 'MomSallyRoute#model');

return Ember.RSVP.reject({
msg: 'did it broke?'
});
},

actions: {
error(err) {
step(2, 'MomSallyRoute#error');

handledError = err;

return true;
}
}
});

bootApplication('/grandma/mom/sally');
});

QUnit.test('errors that are bubbled are thrown at a higher level if not handled', function() {
expect(3);

var handledError;

templates['grandma'] = 'GRANDMA {{outlet}}';

Router.map(function() {
this.route('grandma', function() {
this.route('mom', { resetNamespace: true }, function() {
this.route('sally');
});
});
});

App.ApplicationController = Ember.Controller.extend();

App.MomSallyRoute = Ember.Route.extend({
model() {
step(1, 'MomSallyRoute#model');

return Ember.RSVP.reject({
msg: 'did it broke?'
});
},

actions: {
error(err) {
step(2, 'MomSallyRoute#error');

handledError = err;

return true;
}
}
});

throws(
function() {
bootApplication('/grandma/mom/sally');
},
function(err) {
return err.msg === 'did it broke?';
},
'Correct error was thrown'
);
});

QUnit.test('Handled errors that are thrown through rejection aren\'t swallowed', function() {
expect(4);

Expand Down

0 comments on commit 2356dd6

Please sign in to comment.