Skip to content

Commit

Permalink
fix(Transition): Reject Transition promise when onBefore error
Browse files Browse the repository at this point in the history
closes #2561
  • Loading branch information
christopherthielen committed Mar 27, 2016
1 parent 0c123c3 commit 4b6d56f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/transition/transitionHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class TransitionHook {
try {
results.push(hooks[i].invokeStep(locals));
} catch (exception) {
if (!swallowExceptions) throw exception;
if (!swallowExceptions) return REJECT.aborted(exception);
console.log("Swallowed exception during synchronous hook handler: " + exception); // TODO: What to do here?
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/transitionSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ describe('transition', function () {
expect(result.get().reject.message).toEqual("transition failed");
}));

it('$transition$.promise should reject on error in synchronous hooks', inject(function($transitions, $q) {
var result = new PromiseResult();

transitionProvider.onBefore({ from: "*", to: "third" }, function($transition$) {
result.setPromise($transition$.promise);
throw new Error("transition failed");
});

try {
makeTransition("", "third").run();
} catch (e) {}
$q.flush();

expect(result.called()).toEqual({ resolve: false, reject: true, complete: true });
expect(result.get().reject.detail.message).toEqual("transition failed");
}));

it('should inject $transition$', inject(function($transitions, $q) {
var t = null;

Expand Down

0 comments on commit 4b6d56f

Please sign in to comment.