Last active
July 17, 2023 12:13
-
-
Save LayZeeDK/0ec8fd8f3499f019bf85c07f5a3259fd to your computer and use it in GitHub Desktop.
Spectacular 15 Feature testing API design
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Angular Testing Library + Spectacular 0.5 | |
const { | |
fixture: { | |
debugElement: { injector }, | |
}, | |
} = await render(SpectacularAppComponent, { | |
excludeComponentDeclaration: true, | |
imports: [ | |
SpectacularFeatureTestingModule.withFeature({ | |
featureModule: HeroesModule, | |
featurePath: 'heroes', | |
}), | |
// does this work? | |
RouterTestingModule.withRoutes([], { | |
onSameUrlNavigation: 'reload', | |
}), | |
], | |
}); | |
const router = injector.get(SpectacularFeatureRouter); | |
const location = injector.get(SpectacularFeatureLocation); | |
await router.navigateByUrl('~/'); | |
expect(location.path()).toBe('~/'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Angular Testing Library + Spectacular >=15 | |
const { | |
fixture: { | |
debugElement: { injector }, | |
}, | |
} = await render(TestAppComponent, { | |
routes: [{ path: 'heroes', loadChildren: () => HeroesModule }], | |
providers: [ | |
provideSpectacularFeatureTesting( | |
withFeaturePath('heroes'), | |
withInitialFeatureNavigation(), | |
withRouterConfig({ | |
onSameUrlNavigation: 'reload', | |
}) | |
), | |
], | |
}); | |
const location = injector.get(SpectacularFeatureLocation); | |
expect(location.path()).toBe('~/'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Angular Testing Library | |
const { | |
fixture: { | |
debugElement: { injector }, | |
}, | |
navigate, | |
} = await render(TestAppComponent, { | |
routes: [{ path: 'heroes', loadChildren: () => HeroesModule }], | |
imports: [ | |
// does this work? | |
RouterTestingModule.withRoutes([], { | |
onSameUrlNavigation: 'reload', | |
}), | |
], | |
}); | |
const ngZone = injector.get(NgZone); | |
const location = injector.get(Location); | |
await ngZone?.run(() => navigate('/heroes')); | |
expect(location.path()).toBe('/heroes'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TestBed + RouterTestingHarness | |
TestBed.configureTestingModule({ | |
providers: [ | |
provideRouter( | |
[{ path: 'heroes', loadChildren: () => HeroesModule }], | |
withRouterConfig({ | |
onSameUrlNavigation: 'reload', | |
}) | |
), | |
provideLocationMocks(), | |
], | |
}); | |
const harness = await RouterTestingHarness.create('/heroes'); | |
const location = TestBed.inject(Location); | |
expect(location.path()).toBe('/heroes'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TestBed + Spectacular 0.5 | |
const harness = createFeatureHarness({ | |
featureModule: HeroesModule, | |
featurePath: 'heroes', | |
routerOptions: { | |
onSameUrlNavigation: 'reload', | |
}, | |
}); | |
expect(harness.location.path()).toBe('~/'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TestBed + Spectacular >=15 | |
const harnesss = createFeatureHarness({ | |
featurePath: 'heroes', | |
routes: [{ path: 'heroes', loadChildren: () => HeroesModule }], | |
routerOptions: { | |
onSameUrlNavigation: 'reload', | |
}, | |
}); | |
expect(harness.location.path()).toBe('~/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment