Setting up a routed feature
💡 Tip Lazy loading a feature isn't a requirement in an integration test.
Standalone feature routes​
To set up standalone feature routes for a feature test, specify the featurePath option and add a route to the routes array option that wraps the standalone routes.
- Feature harness
- Angular Testing Library
Use createFeatureHarness to create a feature testing harness.
import { createFeatureHarness } from '@ngworker/spectacular';
import {
crisisCenterPath,
crisisCenterRoutes,
} from '@tour-of-heroes/crisis-center';
function setup() {
const harness = createFeatureHarness({
featurePath: crisisCenterPath,
routes: [
{ path: crisisCenterPath, loadChildren: () => crisisCenterRoutes },
],
});
return {
harness,
};
}
Using Angular Testing Library, pass SpectacularAppComponent as the first argument to render and add provideSpectacularFeatureTesting to the providers array option.
import {
provideSpectacularFeatureTesting,
SpectacularAppComponent,
} from '@ngworker/spectacular';
import { render } from '@testing-library/angular';
import {
crisisCenterPath,
crisisCenterRoutes,
} from '@tour-of-heroes/crisis-center';
async function setup() {
await render(SpectacularAppComponent, {
providers: [
provideSpectacularFeatureTesting({
featurePath: crisisCenterPath,
routes: [
{ path: crisisCenterPath, loadChildren: () => crisisCenterRoutes },
],
}),
],
});
}
Routed feature module​
To set up a routed feature for a feature test, specify the featurePath option and add a route to the routes array option that wraps the routed feature module.
- Feature harness
- Angular Testing Library
Use createFeatureHarness to create a feature testing harness.
import { createFeatureHarness } from '@ngworker/spectacular';
import {
CrisisCenterModule,
crisisCenterPath,
} from '@tour-of-heroes/crisis-center';
function setup() {
const harness = createFeatureHarness({
featurePath: crisisCenterPath,
routes: [
{ path: crisisCenterPath, loadChildren: () => CrisisCenterModule },
],
});
return {
harness,
};
}
Using Angular Testing Library, pass SpectacularAppComponent as the first argument to render and add provideSpectacularFeatureTesting to the providers array option.
import {
provideSpectacularFeatureTesting,
SpectacularAppComponent,
} from '@ngworker/spectacular';
import { render } from '@testing-library/angular';
import {
CrisisCenterModule,
crisisCenterRoutes,
} from '@tour-of-heroes/crisis-center';
async function setup() {
await render(SpectacularAppComponent, {
providers: [
provideSpectacularFeatureTesting({
featurePath: crisisCenterPath,
routes: [
{ path: crisisCenterPath, loadChildren: () => CrisisCenterModule },
],
}),
],
});
}