From 5c95b376b5d12d594e17de2f20ba8fa03b93be1b Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Tue, 18 Aug 2015 11:30:32 -0700 Subject: [PATCH] fix(router): subscribe should return subscription Closes #3491 Closes #3695 --- modules/angular2/src/router/router.ts | 4 ++-- modules/angular2/test/router/router_spec.ts | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/angular2/src/router/router.ts b/modules/angular2/src/router/router.ts index 020c68bc7f..8f38824289 100644 --- a/modules/angular2/src/router/router.ts +++ b/modules/angular2/src/router/router.ts @@ -242,8 +242,8 @@ export class Router { /** * Subscribe to URL updates from the router */ - subscribe(onNext: (value: any) => void): void { - ObservableWrapper.subscribe(this._subject, onNext); + subscribe(onNext: (value: any) => void): Object { + return ObservableWrapper.subscribe(this._subject, onNext); } diff --git a/modules/angular2/test/router/router_spec.ts b/modules/angular2/test/router/router_spec.ts index b800d6164d..db23c7dec5 100644 --- a/modules/angular2/test/router/router_spec.ts +++ b/modules/angular2/test/router/router_spec.ts @@ -12,7 +12,7 @@ import { SpyObject } from 'angular2/test_lib'; import {IMPLEMENTS, Type} from 'angular2/src/facade/lang'; -import {Promise, PromiseWrapper} from 'angular2/src/facade/async'; +import {Promise, PromiseWrapper, ObservableWrapper} from 'angular2/src/facade/async'; import {ListWrapper} from 'angular2/src/facade/collection'; import {Router, RootRouter} from 'angular2/src/router/router'; @@ -122,6 +122,12 @@ export function main() { .toThrowError(`Link "${ListWrapper.toJSON(['/'])}" must include a route name.`); }); + it('should, when subscribed to, return a disposable subscription', () => { + expect(() => { + var subscription = router.subscribe((_) => {}); + ObservableWrapper.dispose(subscription); + }).not.toThrow(); + }); it('should generate URLs from the root component when the path starts with /', () => { router.config([new Route({path: '/first/...', component: DummyParentComp, as: 'firstCmp'})]);