diff --git a/src/directives/uiSref.ts b/src/directives/uiSref.ts index c332f41a5..3b9055f90 100644 --- a/src/directives/uiSref.ts +++ b/src/directives/uiSref.ts @@ -1,4 +1,4 @@ -import { UIRouter, extend, Obj, TransitionOptions, TargetState, isNumber, isNullOrUndefined } from '@uirouter/core'; +import { UIRouter, extend, Obj, StateOrName, TransitionOptions, TargetState, isNumber, isNullOrUndefined } from '@uirouter/core'; import { Directive, Inject, @@ -87,7 +87,7 @@ export class UISref implements OnChanges { * Home * ``` */ - @Input('uiSref') state: string; + @Input('uiSref') state: StateOrName; /** * `@Input('uiParams')` The parameter values to use (as key/values) @@ -132,7 +132,7 @@ export class UISref implements OnChanges { } /** @internal */ - set uiSref(val: string) { + set uiSref(val: StateOrName) { this.state = val; this.update(); } diff --git a/test/uiSref/uiSref.spec.ts b/test/uiSref/uiSref.spec.ts index 8ac4bd320..057a4b7d0 100644 --- a/test/uiSref/uiSref.spec.ts +++ b/test/uiSref/uiSref.spec.ts @@ -5,7 +5,7 @@ import { By } from '@angular/platform-browser'; import { UIRouterModule } from '../../src/uiRouterNgModule'; import { UISref } from '../../src/directives/uiSref'; -import { UIRouter, TargetState, TransitionOptions } from '@uirouter/core'; +import { UIRouter, StateDeclaration, TargetState, TransitionOptions } from '@uirouter/core'; import { Subscription } from 'rxjs'; import { clickOnElement } from '../testUtils'; @@ -14,6 +14,7 @@ describe('uiSref', () => { template: ` + `, }) class TestComponent { @@ -22,6 +23,7 @@ describe('uiSref', () => { linkAOptions: TransitionOptions; targetA: string; linkB: string; + linkC: StateDeclaration; @ViewChildren(UISref) srefs: QueryList; @@ -35,6 +37,7 @@ describe('uiSref', () => { this.linkAOptions = null; this.targetA = ''; this.linkB = ''; + this.linkC = {}; } } @@ -108,6 +111,16 @@ describe('uiSref', () => { expect(gospy.mock.calls[0][0]).toBe('stateref'); }); + it('should handle when param is stateDeclaration', () => { + const { fixture, srefElements, router } = setup(); + const gospy = jest.spyOn(router.stateService, 'go'); + fixture.componentInstance.linkC = { name: 'stateref' }; + fixture.detectChanges(); + clickOnElement(srefElements[2]); + expect(gospy).toHaveBeenCalledTimes(1); + expect(gospy.mock.calls[0][0]).toEqual({ name: 'stateref' }); + }); + it('should ignore the click event when target is _blank', () => { const { fixture, srefElements, router } = setup(); const gospy = jest.spyOn(router.stateService, 'go');