diff --git a/change/@ni-nimble-angular-16d68d67-9ecc-41b3-b7aa-cb52dbd66da4.json b/change/@ni-nimble-angular-16d68d67-9ecc-41b3-b7aa-cb52dbd66da4.json
new file mode 100644
index 0000000000..c19e126405
--- /dev/null
+++ b/change/@ni-nimble-angular-16d68d67-9ecc-41b3-b7aa-cb52dbd66da4.json
@@ -0,0 +1,7 @@
+{
+ "type": "none",
+ "comment": "Angular router link test improvements",
+ "packageName": "@ni/nimble-angular",
+ "email": "jattasNI@users.noreply.github.com",
+ "dependentChangeType": "none"
+}
diff --git a/packages/angular-workspace/nimble-angular/src/directives/anchor-button/tests/nimble-anchor-button-router-link-with-href.directive.spec.ts b/packages/angular-workspace/nimble-angular/src/directives/anchor-button/tests/nimble-anchor-button-router-link-with-href.directive.spec.ts
index 92cb9a098f..c5a7741bd3 100644
--- a/packages/angular-workspace/nimble-angular/src/directives/anchor-button/tests/nimble-anchor-button-router-link-with-href.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/src/directives/anchor-button/tests/nimble-anchor-button-router-link-with-href.directive.spec.ts
@@ -1,8 +1,9 @@
import { Component, ElementRef, Sanitizer, SecurityContext, ViewChild } from '@angular/core';
-import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
-import { Router } from '@angular/router';
+import { fakeAsync, TestBed, tick } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
+import { provideRouter, Router } from '@angular/router';
import { CommonModule, Location } from '@angular/common';
-import { RouterTestingModule } from '@angular/router/testing';
+import { RouterTestingHarness } from '@angular/router/testing';
import { parameterizeSpec } from '@ni/jasmine-parameterized';
import { processUpdates } from '../../../testing/async-helpers';
import { NimbleAnchorButtonModule } from '../nimble-anchor-button.module';
@@ -14,7 +15,6 @@ describe('Nimble anchor button RouterLinkWithHrefDirective', () => {
Anchor text
-
`
})
class TestHostComponent {
@@ -25,7 +25,6 @@ describe('Nimble anchor button RouterLinkWithHrefDirective', () => {
class BlankComponent { }
let anchorButton: AnchorButton;
- let fixture: ComponentFixture;
let testHostComponent: TestHostComponent;
let router: Router;
let location: Location;
@@ -33,41 +32,40 @@ describe('Nimble anchor button RouterLinkWithHrefDirective', () => {
let routerNavigateByUrlSpy: jasmine.Spy;
let anchorClickHandlerSpy: jasmine.Spy;
let sanitizer: jasmine.SpyObj;
+ let harness: RouterTestingHarness;
- beforeEach(() => {
+ beforeEach(async () => {
sanitizer = jasmine.createSpyObj('Sanitizer', ['sanitize']);
sanitizer.sanitize.and.callFake((_, value: string) => value);
TestBed.configureTestingModule({
declarations: [TestHostComponent, BlankComponent],
- imports: [NimbleAnchorButtonModule,
+ imports: [
+ NimbleAnchorButtonModule,
CommonModule,
- RouterTestingModule.withRoutes([
- { path: '', redirectTo: '/start', pathMatch: 'full' },
- { path: 'page1', component: BlankComponent },
- { path: 'start', component: TestHostComponent }
- ], { useHash: true })
],
providers: [
- { provide: Sanitizer, useValue: sanitizer }
+ { provide: Sanitizer, useValue: sanitizer },
+ provideRouter([
+ { path: 'page1', component: BlankComponent },
+ { path: '', component: TestHostComponent }
+ ]),
]
});
+ harness = await RouterTestingHarness.create('');
});
- beforeEach(fakeAsync(() => {
+ beforeEach(() => {
router = TestBed.inject(Router);
location = TestBed.inject(Location);
- fixture = TestBed.createComponent(TestHostComponent);
- testHostComponent = fixture.componentInstance;
+ testHostComponent = harness.fixture.debugElement.query(By.directive(TestHostComponent)).componentInstance as TestHostComponent;
anchorButton = testHostComponent.anchor.nativeElement;
- fixture.detectChanges();
- tick();
processUpdates();
innerAnchor = anchorButton!.shadowRoot!.querySelector('a')!;
routerNavigateByUrlSpy = spyOn(router, 'navigateByUrl').and.callThrough();
- anchorClickHandlerSpy = jasmine.createSpy('click');
+ anchorClickHandlerSpy = jasmine.createSpy('click').and.callFake((event: Event) => event.preventDefault());
innerAnchor!.addEventListener('click', anchorClickHandlerSpy);
- }));
+ });
afterEach(() => {
processUpdates();
diff --git a/packages/angular-workspace/nimble-angular/src/directives/anchor-button/tests/nimble-anchor-button-router-link.directive.spec.ts b/packages/angular-workspace/nimble-angular/src/directives/anchor-button/tests/nimble-anchor-button-router-link.directive.spec.ts
index d64bb909d2..06d8232b2e 100644
--- a/packages/angular-workspace/nimble-angular/src/directives/anchor-button/tests/nimble-anchor-button-router-link.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/src/directives/anchor-button/tests/nimble-anchor-button-router-link.directive.spec.ts
@@ -1,7 +1,6 @@
import { Component } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { CommonModule } from '@angular/common';
-import { RouterTestingModule } from '@angular/router/testing';
import { processUpdates } from '../../../testing/async-helpers';
import { NimbleAnchorButtonModule } from '../nimble-anchor-button.module';
@@ -23,8 +22,7 @@ describe('Nimble anchor button RouterLinkDirective', () => {
imports: [
NimbleAnchorButtonModule,
CommonModule,
- RouterTestingModule.withRoutes([{ path: '', component: TestHostComponent, pathMatch: 'full' }], { useHash: true })
- ]
+ ],
});
});
diff --git a/packages/angular-workspace/nimble-angular/src/directives/anchor-menu-item/tests/nimble-anchor-menu-item-router-link-with-href.directive.spec.ts b/packages/angular-workspace/nimble-angular/src/directives/anchor-menu-item/tests/nimble-anchor-menu-item-router-link-with-href.directive.spec.ts
index e80ad56781..e43ef5447f 100644
--- a/packages/angular-workspace/nimble-angular/src/directives/anchor-menu-item/tests/nimble-anchor-menu-item-router-link-with-href.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/src/directives/anchor-menu-item/tests/nimble-anchor-menu-item-router-link-with-href.directive.spec.ts
@@ -1,8 +1,9 @@
import { Component, ElementRef, Sanitizer, SecurityContext, ViewChild } from '@angular/core';
-import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
-import { Router } from '@angular/router';
+import { fakeAsync, TestBed, tick } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
+import { provideRouter, Router } from '@angular/router';
import { CommonModule, Location } from '@angular/common';
-import { RouterTestingModule } from '@angular/router/testing';
+import { RouterTestingHarness } from '@angular/router/testing';
import { parameterizeSpec } from '@ni/jasmine-parameterized';
import { processUpdates } from '../../../testing/async-helpers';
import { NimbleAnchorMenuItemModule } from '../nimble-anchor-menu-item.module';
@@ -14,7 +15,6 @@ describe('Nimble anchor menu item RouterLinkWithHrefDirective', () => {
Anchor text
-
`
})
class TestHostComponent {
@@ -25,7 +25,6 @@ describe('Nimble anchor menu item RouterLinkWithHrefDirective', () => {
class BlankComponent { }
let menuItem: AnchorMenuItem;
- let fixture: ComponentFixture;
let testHostComponent: TestHostComponent;
let router: Router;
let location: Location;
@@ -33,41 +32,40 @@ describe('Nimble anchor menu item RouterLinkWithHrefDirective', () => {
let routerNavigateByUrlSpy: jasmine.Spy;
let anchorClickHandlerSpy: jasmine.Spy;
let sanitizer: jasmine.SpyObj;
+ let harness: RouterTestingHarness;
- beforeEach(() => {
+ beforeEach(async () => {
sanitizer = jasmine.createSpyObj('Sanitizer', ['sanitize']);
sanitizer.sanitize.and.callFake((_, value: string) => value);
TestBed.configureTestingModule({
declarations: [TestHostComponent, BlankComponent],
- imports: [NimbleAnchorMenuItemModule,
+ imports: [
+ NimbleAnchorMenuItemModule,
CommonModule,
- RouterTestingModule.withRoutes([
- { path: '', redirectTo: '/start', pathMatch: 'full' },
- { path: 'page1', component: BlankComponent },
- { path: 'start', component: TestHostComponent }
- ], { useHash: true })
],
providers: [
- { provide: Sanitizer, useValue: sanitizer }
+ { provide: Sanitizer, useValue: sanitizer },
+ provideRouter([
+ { path: 'page1', component: BlankComponent },
+ { path: '', component: TestHostComponent }
+ ]),
]
});
+ harness = await RouterTestingHarness.create('');
});
- beforeEach(fakeAsync(() => {
+ beforeEach(() => {
router = TestBed.inject(Router);
location = TestBed.inject(Location);
- fixture = TestBed.createComponent(TestHostComponent);
- testHostComponent = fixture.componentInstance;
+ testHostComponent = harness.fixture.debugElement.query(By.directive(TestHostComponent)).componentInstance as TestHostComponent;
menuItem = testHostComponent.menuItem.nativeElement;
- fixture.detectChanges();
- tick();
processUpdates();
innerAnchor = menuItem!.shadowRoot!.querySelector('a')!;
routerNavigateByUrlSpy = spyOn(router, 'navigateByUrl').and.callThrough();
- anchorClickHandlerSpy = jasmine.createSpy('click');
+ anchorClickHandlerSpy = jasmine.createSpy('click').and.callFake((event: Event) => event.preventDefault());
innerAnchor!.addEventListener('click', anchorClickHandlerSpy);
- }));
+ });
afterEach(() => {
processUpdates();
diff --git a/packages/angular-workspace/nimble-angular/src/directives/anchor-menu-item/tests/nimble-anchor-menu-item-router-link.directive.spec.ts b/packages/angular-workspace/nimble-angular/src/directives/anchor-menu-item/tests/nimble-anchor-menu-item-router-link.directive.spec.ts
index 0c2b345e36..9cf045a924 100644
--- a/packages/angular-workspace/nimble-angular/src/directives/anchor-menu-item/tests/nimble-anchor-menu-item-router-link.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/src/directives/anchor-menu-item/tests/nimble-anchor-menu-item-router-link.directive.spec.ts
@@ -1,7 +1,6 @@
import { Component } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { CommonModule } from '@angular/common';
-import { RouterTestingModule } from '@angular/router/testing';
import { processUpdates } from '../../../testing/async-helpers';
import { NimbleAnchorMenuItemModule } from '../nimble-anchor-menu-item.module';
@@ -20,11 +19,10 @@ describe('Nimble anchor menu item RouterLinkDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestHostComponent],
- imports: [NimbleAnchorMenuItemModule,
- CommonModule,
- RouterTestingModule.withRoutes([{ path: '', component: TestHostComponent, pathMatch: 'full' }
- ], { useHash: true })
- ]
+ imports: [
+ NimbleAnchorMenuItemModule,
+ CommonModule
+ ],
});
});
diff --git a/packages/angular-workspace/nimble-angular/src/directives/anchor-tab/tests/nimble-anchor-tab-router-link-with-href.directive.spec.ts b/packages/angular-workspace/nimble-angular/src/directives/anchor-tab/tests/nimble-anchor-tab-router-link-with-href.directive.spec.ts
index d8bebb9743..008aa71d81 100644
--- a/packages/angular-workspace/nimble-angular/src/directives/anchor-tab/tests/nimble-anchor-tab-router-link-with-href.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/src/directives/anchor-tab/tests/nimble-anchor-tab-router-link-with-href.directive.spec.ts
@@ -1,8 +1,9 @@
import { Component, ElementRef, Sanitizer, SecurityContext, ViewChild } from '@angular/core';
-import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
-import { Router } from '@angular/router';
+import { fakeAsync, TestBed, tick } from '@angular/core/testing';
+import { provideRouter, Router } from '@angular/router';
import { CommonModule, Location } from '@angular/common';
-import { RouterTestingModule } from '@angular/router/testing';
+import { By } from '@angular/platform-browser';
+import { RouterTestingHarness } from '@angular/router/testing';
import { parameterizeSpec } from '@ni/jasmine-parameterized';
import { processUpdates } from '../../../testing/async-helpers';
import { NimbleAnchorTabModule } from '../nimble-anchor-tab.module';
@@ -14,7 +15,6 @@ describe('Nimble anchor tab RouterLinkWithHrefDirective', () => {
Anchor text
-
`
})
class TestHostComponent {
@@ -25,7 +25,6 @@ describe('Nimble anchor tab RouterLinkWithHrefDirective', () => {
class BlankComponent { }
let anchorTab: AnchorTab;
- let fixture: ComponentFixture;
let testHostComponent: TestHostComponent;
let router: Router;
let location: Location;
@@ -33,41 +32,40 @@ describe('Nimble anchor tab RouterLinkWithHrefDirective', () => {
let routerNavigateByUrlSpy: jasmine.Spy;
let anchorClickHandlerSpy: jasmine.Spy;
let sanitizer: jasmine.SpyObj;
+ let harness: RouterTestingHarness;
- beforeEach(() => {
+ beforeEach(async () => {
sanitizer = jasmine.createSpyObj('Sanitizer', ['sanitize']);
sanitizer.sanitize.and.callFake((_, value: string) => value);
TestBed.configureTestingModule({
declarations: [TestHostComponent, BlankComponent],
- imports: [NimbleAnchorTabModule,
+ imports: [
+ NimbleAnchorTabModule,
CommonModule,
- RouterTestingModule.withRoutes([
- { path: '', redirectTo: '/start', pathMatch: 'full' },
- { path: 'page1', component: BlankComponent },
- { path: 'start', component: TestHostComponent }
- ], { useHash: true })
],
providers: [
- { provide: Sanitizer, useValue: sanitizer }
+ { provide: Sanitizer, useValue: sanitizer },
+ provideRouter([
+ { path: 'page1', component: BlankComponent },
+ { path: '', component: TestHostComponent }
+ ]),
]
});
+ harness = await RouterTestingHarness.create('');
});
- beforeEach(fakeAsync(() => {
+ beforeEach(() => {
router = TestBed.inject(Router);
location = TestBed.inject(Location);
- fixture = TestBed.createComponent(TestHostComponent);
- testHostComponent = fixture.componentInstance;
+ testHostComponent = harness.fixture.debugElement.query(By.directive(TestHostComponent)).componentInstance as TestHostComponent;
anchorTab = testHostComponent.anchorTab.nativeElement;
- fixture.detectChanges();
- tick();
processUpdates();
innerAnchor = anchorTab!.shadowRoot!.querySelector('a')!;
routerNavigateByUrlSpy = spyOn(router, 'navigateByUrl').and.callThrough();
- anchorClickHandlerSpy = jasmine.createSpy('click');
+ anchorClickHandlerSpy = jasmine.createSpy('click').and.callFake((event: Event) => event.preventDefault());
innerAnchor!.addEventListener('click', anchorClickHandlerSpy);
- }));
+ });
afterEach(() => {
processUpdates();
diff --git a/packages/angular-workspace/nimble-angular/src/directives/anchor-tab/tests/nimble-anchor-tab-router-link.directive.spec.ts b/packages/angular-workspace/nimble-angular/src/directives/anchor-tab/tests/nimble-anchor-tab-router-link.directive.spec.ts
index 85576f3d97..e4a25a5bd8 100644
--- a/packages/angular-workspace/nimble-angular/src/directives/anchor-tab/tests/nimble-anchor-tab-router-link.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/src/directives/anchor-tab/tests/nimble-anchor-tab-router-link.directive.spec.ts
@@ -1,7 +1,6 @@
import { Component } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { CommonModule } from '@angular/common';
-import { RouterTestingModule } from '@angular/router/testing';
import { processUpdates } from '../../../testing/async-helpers';
import { NimbleAnchorTabModule } from '../nimble-anchor-tab.module';
@@ -20,12 +19,10 @@ describe('Nimble anchor tab RouterLinkDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestHostComponent],
- imports: [NimbleAnchorTabModule,
+ imports: [
+ NimbleAnchorTabModule,
CommonModule,
- RouterTestingModule.withRoutes([
- { path: '', component: TestHostComponent, pathMatch: 'full' }
- ], { useHash: true })
- ]
+ ],
});
});
diff --git a/packages/angular-workspace/nimble-angular/src/directives/anchor-tree-item/tests/nimble-anchor-tree-item-router-link-with-href.directive.spec.ts b/packages/angular-workspace/nimble-angular/src/directives/anchor-tree-item/tests/nimble-anchor-tree-item-router-link-with-href.directive.spec.ts
index b1a2737fcb..f0b25f0291 100644
--- a/packages/angular-workspace/nimble-angular/src/directives/anchor-tree-item/tests/nimble-anchor-tree-item-router-link-with-href.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/src/directives/anchor-tree-item/tests/nimble-anchor-tree-item-router-link-with-href.directive.spec.ts
@@ -1,8 +1,9 @@
import { Component, ElementRef, Sanitizer, SecurityContext, ViewChild } from '@angular/core';
-import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
-import { Router } from '@angular/router';
+import { fakeAsync, TestBed, tick } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
+import { provideRouter, Router } from '@angular/router';
import { CommonModule, Location } from '@angular/common';
-import { RouterTestingModule } from '@angular/router/testing';
+import { RouterTestingHarness } from '@angular/router/testing';
import { parameterizeSpec } from '@ni/jasmine-parameterized';
import { processUpdates } from '../../../testing/async-helpers';
import { NimbleAnchorTreeItemModule } from '../nimble-anchor-tree-item.module';
@@ -14,7 +15,6 @@ describe('Nimble anchor tree item RouterLinkWithHrefDirective', () => {
Anchor text
-
`
})
class TestHostComponent {
@@ -25,7 +25,6 @@ describe('Nimble anchor tree item RouterLinkWithHrefDirective', () => {
class BlankComponent { }
let anchorTreeItem: AnchorTreeItem;
- let fixture: ComponentFixture;
let testHostComponent: TestHostComponent;
let router: Router;
let location: Location;
@@ -33,41 +32,40 @@ describe('Nimble anchor tree item RouterLinkWithHrefDirective', () => {
let routerNavigateByUrlSpy: jasmine.Spy;
let anchorClickHandlerSpy: jasmine.Spy;
let sanitizer: jasmine.SpyObj;
+ let harness: RouterTestingHarness;
- beforeEach(() => {
+ beforeEach(async () => {
sanitizer = jasmine.createSpyObj('Sanitizer', ['sanitize']);
sanitizer.sanitize.and.callFake((_, value: string) => value);
TestBed.configureTestingModule({
declarations: [TestHostComponent, BlankComponent],
- imports: [NimbleAnchorTreeItemModule,
+ imports: [
+ NimbleAnchorTreeItemModule,
CommonModule,
- RouterTestingModule.withRoutes([
- { path: '', redirectTo: '/start', pathMatch: 'full' },
- { path: 'page1', component: BlankComponent },
- { path: 'start', component: TestHostComponent }
- ], { useHash: true })
],
providers: [
- { provide: Sanitizer, useValue: sanitizer }
+ { provide: Sanitizer, useValue: sanitizer },
+ provideRouter([
+ { path: 'page1', component: BlankComponent },
+ { path: '', component: TestHostComponent }
+ ]),
]
});
+ harness = await RouterTestingHarness.create('');
});
- beforeEach(fakeAsync(() => {
+ beforeEach(() => {
router = TestBed.inject(Router);
location = TestBed.inject(Location);
- fixture = TestBed.createComponent(TestHostComponent);
- testHostComponent = fixture.componentInstance;
+ testHostComponent = harness.fixture.debugElement.query(By.directive(TestHostComponent)).componentInstance as TestHostComponent;
anchorTreeItem = testHostComponent.treeItem.nativeElement;
- fixture.detectChanges();
- tick();
processUpdates();
innerAnchor = anchorTreeItem!.shadowRoot!.querySelector('a')!;
routerNavigateByUrlSpy = spyOn(router, 'navigateByUrl').and.callThrough();
- anchorClickHandlerSpy = jasmine.createSpy('click');
+ anchorClickHandlerSpy = jasmine.createSpy('click').and.callFake((event: Event) => event.preventDefault());
innerAnchor!.addEventListener('click', anchorClickHandlerSpy);
- }));
+ });
afterEach(() => {
processUpdates();
diff --git a/packages/angular-workspace/nimble-angular/src/directives/anchor-tree-item/tests/nimble-anchor-tree-item-router-link.directive.spec.ts b/packages/angular-workspace/nimble-angular/src/directives/anchor-tree-item/tests/nimble-anchor-tree-item-router-link.directive.spec.ts
index 17fd45c5e0..4abd871605 100644
--- a/packages/angular-workspace/nimble-angular/src/directives/anchor-tree-item/tests/nimble-anchor-tree-item-router-link.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/src/directives/anchor-tree-item/tests/nimble-anchor-tree-item-router-link.directive.spec.ts
@@ -1,7 +1,6 @@
import { Component } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { CommonModule } from '@angular/common';
-import { RouterTestingModule } from '@angular/router/testing';
import { processUpdates } from '../../../testing/async-helpers';
import { NimbleAnchorTreeItemModule } from '../nimble-anchor-tree-item.module';
@@ -23,8 +22,7 @@ describe('Nimble anchor tree item RouterLinkDirective', () => {
imports: [
NimbleAnchorTreeItemModule,
CommonModule,
- RouterTestingModule.withRoutes([{ path: '', component: TestHostComponent, pathMatch: 'full' }], { useHash: true })
- ]
+ ],
});
});
diff --git a/packages/angular-workspace/nimble-angular/src/directives/anchor/tests/nimble-anchor-router-link-with-href.directive.spec.ts b/packages/angular-workspace/nimble-angular/src/directives/anchor/tests/nimble-anchor-router-link-with-href.directive.spec.ts
index 6895081b77..766a67a4c8 100644
--- a/packages/angular-workspace/nimble-angular/src/directives/anchor/tests/nimble-anchor-router-link-with-href.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/src/directives/anchor/tests/nimble-anchor-router-link-with-href.directive.spec.ts
@@ -1,8 +1,9 @@
import { Component, ElementRef, Sanitizer, SecurityContext, ViewChild } from '@angular/core';
-import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
-import { Router } from '@angular/router';
+import { fakeAsync, TestBed, tick } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
+import { provideRouter, Router } from '@angular/router';
import { CommonModule, Location } from '@angular/common';
-import { RouterTestingModule } from '@angular/router/testing';
+import { RouterTestingHarness } from '@angular/router/testing';
import { parameterizeSpec } from '@ni/jasmine-parameterized';
import { processUpdates } from '../../../testing/async-helpers';
import { NimbleAnchorModule } from '../nimble-anchor.module';
@@ -14,7 +15,6 @@ describe('Nimble anchor RouterLinkWithHrefDirective', () => {
Anchor text
-
`
})
class TestHostComponent {
@@ -25,7 +25,6 @@ describe('Nimble anchor RouterLinkWithHrefDirective', () => {
class BlankComponent { }
let anchor: Anchor;
- let fixture: ComponentFixture;
let testHostComponent: TestHostComponent;
let router: Router;
let location: Location;
@@ -33,8 +32,9 @@ describe('Nimble anchor RouterLinkWithHrefDirective', () => {
let routerNavigateByUrlSpy: jasmine.Spy;
let anchorClickHandlerSpy: jasmine.Spy;
let sanitizer: jasmine.SpyObj;
+ let harness: RouterTestingHarness;
- beforeEach(() => {
+ beforeEach(async () => {
sanitizer = jasmine.createSpyObj('Sanitizer', ['sanitize']);
sanitizer.sanitize.and.callFake((_, value: string) => value);
@@ -42,32 +42,29 @@ describe('Nimble anchor RouterLinkWithHrefDirective', () => {
declarations: [TestHostComponent, BlankComponent],
imports: [NimbleAnchorModule,
CommonModule,
- RouterTestingModule.withRoutes([
- { path: '', redirectTo: '/start', pathMatch: 'full' },
- { path: 'page1', component: BlankComponent },
- { path: 'start', component: TestHostComponent }
- ], { useHash: true })
],
providers: [
- { provide: Sanitizer, useValue: sanitizer }
+ { provide: Sanitizer, useValue: sanitizer },
+ provideRouter([
+ { path: 'page1', component: BlankComponent },
+ { path: '', component: TestHostComponent }
+ ]),
]
});
+ harness = await RouterTestingHarness.create('');
});
- beforeEach(fakeAsync(() => {
+ beforeEach(() => {
router = TestBed.inject(Router);
location = TestBed.inject(Location);
- fixture = TestBed.createComponent(TestHostComponent);
- testHostComponent = fixture.componentInstance;
+ testHostComponent = harness.fixture.debugElement.query(By.directive(TestHostComponent)).componentInstance as TestHostComponent;
anchor = testHostComponent.anchor.nativeElement;
- fixture.detectChanges();
- tick();
processUpdates();
innerAnchor = anchor!.shadowRoot!.querySelector('a')!;
routerNavigateByUrlSpy = spyOn(router, 'navigateByUrl').and.callThrough();
- anchorClickHandlerSpy = jasmine.createSpy('click');
+ anchorClickHandlerSpy = jasmine.createSpy('click').and.callFake((event: Event) => event.preventDefault());
innerAnchor!.addEventListener('click', anchorClickHandlerSpy);
- }));
+ });
afterEach(() => {
processUpdates();
diff --git a/packages/angular-workspace/nimble-angular/src/directives/anchor/tests/nimble-anchor-router-link.directive.spec.ts b/packages/angular-workspace/nimble-angular/src/directives/anchor/tests/nimble-anchor-router-link.directive.spec.ts
index e189e98291..72255fc843 100644
--- a/packages/angular-workspace/nimble-angular/src/directives/anchor/tests/nimble-anchor-router-link.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/src/directives/anchor/tests/nimble-anchor-router-link.directive.spec.ts
@@ -1,7 +1,6 @@
import { Component } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { CommonModule } from '@angular/common';
-import { RouterTestingModule } from '@angular/router/testing';
import { processUpdates } from '../../../testing/async-helpers';
import { NimbleAnchorModule } from '../nimble-anchor.module';
@@ -20,10 +19,9 @@ describe('Nimble anchor RouterLinkDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestHostComponent],
- imports: [NimbleAnchorModule,
+ imports: [
+ NimbleAnchorModule,
CommonModule,
- RouterTestingModule.withRoutes([{ path: '', component: TestHostComponent, pathMatch: 'full' }
- ], { useHash: true })
]
});
});
diff --git a/packages/angular-workspace/nimble-angular/src/directives/breadcrumb-item/tests/nimble-breadcrumb-item-router-link-with-href.directive.spec.ts b/packages/angular-workspace/nimble-angular/src/directives/breadcrumb-item/tests/nimble-breadcrumb-item-router-link-with-href.directive.spec.ts
index 7ab306df0f..ecd1990b50 100644
--- a/packages/angular-workspace/nimble-angular/src/directives/breadcrumb-item/tests/nimble-breadcrumb-item-router-link-with-href.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/src/directives/breadcrumb-item/tests/nimble-breadcrumb-item-router-link-with-href.directive.spec.ts
@@ -1,8 +1,9 @@
import { Component, ElementRef, Sanitizer, SecurityContext, ViewChild } from '@angular/core';
-import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
-import { Router } from '@angular/router';
+import { fakeAsync, TestBed, tick } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
+import { provideRouter, Router } from '@angular/router';
import { CommonModule, Location } from '@angular/common';
-import { RouterTestingModule } from '@angular/router/testing';
+import { RouterTestingHarness } from '@angular/router/testing';
import { parameterizeSpec } from '@ni/jasmine-parameterized';
import { processUpdates } from '../../../testing/async-helpers';
import { NimbleBreadcrumbModule } from '../../breadcrumb/nimble-breadcrumb.module';
@@ -17,7 +18,6 @@ describe('Nimble breadcrumb item RouterLinkWithHrefDirective', () => {
Breadcrumb Text
-
`
})
class TestHostComponent {
@@ -28,7 +28,6 @@ describe('Nimble breadcrumb item RouterLinkWithHrefDirective', () => {
class BlankComponent { }
let breadcrumbItem1: BreadcrumbItem;
- let fixture: ComponentFixture;
let testHostComponent: TestHostComponent;
let router: Router;
let location: Location;
@@ -38,44 +37,44 @@ describe('Nimble breadcrumb item RouterLinkWithHrefDirective', () => {
let anchorClickHandlerSpy: jasmine.Spy;
let separatorClickHandlerSpy: jasmine.Spy;
let sanitizer: jasmine.SpyObj;
+ let harness: RouterTestingHarness;
- beforeEach(() => {
+ beforeEach(async () => {
sanitizer = jasmine.createSpyObj('Sanitizer', ['sanitize']);
sanitizer.sanitize.and.callFake((_, value: string) => value);
TestBed.configureTestingModule({
declarations: [TestHostComponent, BlankComponent],
- imports: [NimbleBreadcrumbModule, NimbleBreadcrumbItemModule,
+ imports: [
+ NimbleBreadcrumbModule,
+ NimbleBreadcrumbItemModule,
CommonModule,
- RouterTestingModule.withRoutes([
- { path: '', redirectTo: '/start', pathMatch: 'full' },
- { path: 'page1', component: BlankComponent },
- { path: 'start', component: TestHostComponent }
- ], { useHash: true })
],
providers: [
- { provide: Sanitizer, useValue: sanitizer }
+ { provide: Sanitizer, useValue: sanitizer },
+ provideRouter([
+ { path: 'page1', component: BlankComponent },
+ { path: '', component: TestHostComponent }
+ ])
]
});
+ harness = await RouterTestingHarness.create('');
});
- beforeEach(fakeAsync(() => {
+ beforeEach(() => {
router = TestBed.inject(Router);
location = TestBed.inject(Location);
- fixture = TestBed.createComponent(TestHostComponent);
- testHostComponent = fixture.componentInstance;
+ testHostComponent = harness.fixture.debugElement.query(By.directive(TestHostComponent)).componentInstance as TestHostComponent;
breadcrumbItem1 = testHostComponent.breadcrumbItem1.nativeElement;
- fixture.detectChanges();
- tick();
processUpdates();
anchor = breadcrumbItem1!.shadowRoot!.querySelector('a')!;
separator = breadcrumbItem1!.shadowRoot!.querySelector('.separator')!;
routerNavigateByUrlSpy = spyOn(router, 'navigateByUrl').and.callThrough();
- anchorClickHandlerSpy = jasmine.createSpy('click');
+ anchorClickHandlerSpy = jasmine.createSpy('click').and.callFake((event: Event) => event.preventDefault());
separatorClickHandlerSpy = jasmine.createSpy('click');
anchor.addEventListener('click', anchorClickHandlerSpy);
separator.addEventListener('click', separatorClickHandlerSpy);
- }));
+ });
afterEach(() => {
processUpdates();
diff --git a/packages/angular-workspace/nimble-angular/src/directives/breadcrumb-item/tests/nimble-breadcrumb-item-router-link.directive.spec.ts b/packages/angular-workspace/nimble-angular/src/directives/breadcrumb-item/tests/nimble-breadcrumb-item-router-link.directive.spec.ts
index 4402ece081..b5882b46f2 100644
--- a/packages/angular-workspace/nimble-angular/src/directives/breadcrumb-item/tests/nimble-breadcrumb-item-router-link.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/src/directives/breadcrumb-item/tests/nimble-breadcrumb-item-router-link.directive.spec.ts
@@ -1,7 +1,6 @@
import { Component } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { CommonModule } from '@angular/common';
-import { RouterTestingModule } from '@angular/router/testing';
import { processUpdates } from '../../../testing/async-helpers';
import { NimbleBreadcrumbModule } from '../../breadcrumb/nimble-breadcrumb.module';
import { NimbleBreadcrumbItemModule } from '../nimble-breadcrumb-item.module';
@@ -23,11 +22,11 @@ describe('Nimble breadcrumb item RouterLinkDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestHostComponent],
- imports: [NimbleBreadcrumbModule, NimbleBreadcrumbItemModule,
+ imports: [
+ NimbleBreadcrumbModule,
+ NimbleBreadcrumbItemModule,
CommonModule,
- RouterTestingModule.withRoutes([{ path: '', component: TestHostComponent, pathMatch: 'full' }
- ], { useHash: true })
- ]
+ ],
});
});
diff --git a/packages/angular-workspace/nimble-angular/table-column/anchor/tests/nimble-table-column-anchor-navigation-guard.directive.spec.ts b/packages/angular-workspace/nimble-angular/table-column/anchor/tests/nimble-table-column-anchor-navigation-guard.directive.spec.ts
index 1756358247..a52ed3b7fd 100644
--- a/packages/angular-workspace/nimble-angular/table-column/anchor/tests/nimble-table-column-anchor-navigation-guard.directive.spec.ts
+++ b/packages/angular-workspace/nimble-angular/table-column/anchor/tests/nimble-table-column-anchor-navigation-guard.directive.spec.ts
@@ -76,7 +76,7 @@ describe('Nimble anchor table column navigation guard', () => {
const pageObject = new TablePageObject(testHostComponent.table.nativeElement);
anchor = pageObject.getRenderedCellAnchor(0, 0);
innerAnchor = anchor!.shadowRoot!.querySelector('a')!;
- anchorClickHandlerSpy = jasmine.createSpy('click');
+ anchorClickHandlerSpy = jasmine.createSpy('click').and.callFake((event: Event) => event.preventDefault());
innerAnchor!.addEventListener('click', anchorClickHandlerSpy);
onClickSpy = spyOn(testHostComponent, 'onClick');
@@ -127,7 +127,7 @@ describe('Nimble anchor table column navigation guard', () => {
const pageObject = new TablePageObject(testHostComponent.table.nativeElement);
anchor = pageObject.getRenderedCellAnchor(0, 0);
innerAnchor = anchor!.shadowRoot!.querySelector('a')!;
- anchorClickHandlerSpy = jasmine.createSpy('click');
+ anchorClickHandlerSpy = jasmine.createSpy('click').and.callFake((event: Event) => event.preventDefault());
innerAnchor!.addEventListener('click', anchorClickHandlerSpy);
onClickSpy = spyOn(testHostComponent, 'onClick');
diff --git a/packages/angular-workspace/package.json b/packages/angular-workspace/package.json
index c8350d58cb..2862b6817e 100644
--- a/packages/angular-workspace/package.json
+++ b/packages/angular-workspace/package.json
@@ -7,9 +7,7 @@
"start": "ng serve",
"build": "npm run build:nimble && npm run build:spright && npm run build:application",
"build:nimble": "npm run generate-icons && ng build @ni/nimble-angular",
- "watch:nimble": "npm run generate-icons && ng build @ni/nimble-angular --watch",
"build:spright": "ng build @ni/spright-angular",
- "watch:spright": "ng build @ni/spright-angular --watch",
"build:application": "ng build example-client-app",
"generate-icons": "npm run generate-icons:bundle && npm run generate-icons:run",
"generate-icons:bundle": "rollup --bundleConfigAsCjs --config nimble-angular/build/generate-icons/rollup.config.js",
@@ -20,7 +18,13 @@
"pack:application": "cd dist/example-client-app && npm pack",
"performance": "lhci autorun",
"watch": "ng build --watch --configuration development",
+ "watch-nimble": "npm run generate-icons && ng build @ni/nimble-angular --watch",
+ "watch-spright": "ng build @ni/spright-angular --watch",
+ "tdd-nimble": "ng test @ni/nimble-angular --browsers=Chrome",
+ "tdd-spright": "ng test @ni/spright-angular --browsers=Chrome",
"test": "ng test --watch=false",
+ "test-nimble": "ng test @ni/nimble-angular --watch=false",
+ "test-spright": "ng test @ni/spright-angular --watch=false",
"lint": "ng lint",
"format": "ng lint --fix"
},