Skip to content

Commit fe26fe0

Browse files
authoredDec 2, 2021
feat: Update uiSref input type from string to StateOrName (#943)
1 parent be3ba79 commit fe26fe0

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed
 

‎src/directives/uiSref.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UIRouter, extend, Obj, TransitionOptions, TargetState, isNumber, isNullOrUndefined } from '@uirouter/core';
1+
import { UIRouter, extend, Obj, StateOrName, TransitionOptions, TargetState, isNumber, isNullOrUndefined } from '@uirouter/core';
22
import {
33
Directive,
44
Inject,
@@ -87,7 +87,7 @@ export class UISref implements OnChanges {
8787
* <a uiSref="hoome">Home</a>
8888
* ```
8989
*/
90-
@Input('uiSref') state: string;
90+
@Input('uiSref') state: StateOrName;
9191

9292
/**
9393
* `@Input('uiParams')` The parameter values to use (as key/values)
@@ -132,7 +132,7 @@ export class UISref implements OnChanges {
132132
}
133133

134134
/** @internal */
135-
set uiSref(val: string) {
135+
set uiSref(val: StateOrName) {
136136
this.state = val;
137137
this.update();
138138
}

‎test/uiSref/uiSref.spec.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { By } from '@angular/platform-browser';
55

66
import { UIRouterModule } from '../../src/uiRouterNgModule';
77
import { UISref } from '../../src/directives/uiSref';
8-
import { UIRouter, TargetState, TransitionOptions } from '@uirouter/core';
8+
import { UIRouter, StateDeclaration, TargetState, TransitionOptions } from '@uirouter/core';
99
import { Subscription } from 'rxjs';
1010
import { clickOnElement } from '../testUtils';
1111

@@ -14,6 +14,7 @@ describe('uiSref', () => {
1414
template: `
1515
<a [uiSref]="linkA" [target]="targetA" [uiParams]="linkAParams" [uiOptions]="linkAOptions"></a>
1616
<a [uiSref]="linkB"></a>
17+
<a [uiSref]="linkC"></a>
1718
`,
1819
})
1920
class TestComponent {
@@ -22,6 +23,7 @@ describe('uiSref', () => {
2223
linkAOptions: TransitionOptions;
2324
targetA: string;
2425
linkB: string;
26+
linkC: StateDeclaration;
2527

2628
@ViewChildren(UISref) srefs: QueryList<UISref>;
2729

@@ -35,6 +37,7 @@ describe('uiSref', () => {
3537
this.linkAOptions = null;
3638
this.targetA = '';
3739
this.linkB = '';
40+
this.linkC = {};
3841
}
3942
}
4043

@@ -108,6 +111,16 @@ describe('uiSref', () => {
108111
expect(gospy.mock.calls[0][0]).toBe('stateref');
109112
});
110113

114+
it('should handle when param is stateDeclaration', () => {
115+
const { fixture, srefElements, router } = setup();
116+
const gospy = jest.spyOn(router.stateService, 'go');
117+
fixture.componentInstance.linkC = { name: 'stateref' };
118+
fixture.detectChanges();
119+
clickOnElement(srefElements[2]);
120+
expect(gospy).toHaveBeenCalledTimes(1);
121+
expect(gospy.mock.calls[0][0]).toEqual({ name: 'stateref' });
122+
});
123+
111124
it('should ignore the click event when target is _blank', () => {
112125
const { fixture, srefElements, router } = setup();
113126
const gospy = jest.spyOn(router.stateService, 'go');

0 commit comments

Comments
 (0)
Please sign in to comment.