index.d.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * @license Angular v19.2.4
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import * as i0 from '@angular/core';
  7. import { ModuleWithProviders, WritableSignal, DebugElement, Type } from '@angular/core';
  8. import * as _angular_router from '@angular/router';
  9. import { Routes, ExtraOptions } from '@angular/router';
  10. import { ComponentFixture } from '@angular/core/testing';
  11. /**
  12. * @description
  13. *
  14. * Sets up the router to be used for testing.
  15. *
  16. * The modules sets up the router to be used for testing.
  17. * It provides spy implementations of `Location` and `LocationStrategy`.
  18. *
  19. * @usageNotes
  20. * ### Example
  21. *
  22. * ```ts
  23. * beforeEach(() => {
  24. * TestBed.configureTestingModule({
  25. * imports: [
  26. * RouterModule.forRoot(
  27. * [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]
  28. * )
  29. * ]
  30. * });
  31. * });
  32. * ```
  33. *
  34. * @publicApi
  35. * @deprecated Use `provideRouter` or `RouterModule`/`RouterModule.forRoot` instead.
  36. * This module was previously used to provide a helpful collection of test fakes,
  37. * most notably those for `Location` and `LocationStrategy`. These are generally not
  38. * required anymore, as `MockPlatformLocation` is provided in `TestBed` by default.
  39. * However, you can use them directly with `provideLocationMocks`.
  40. */
  41. declare class RouterTestingModule {
  42. static withRoutes(routes: Routes, config?: ExtraOptions): ModuleWithProviders<RouterTestingModule>;
  43. static ɵfac: i0.ɵɵFactoryDeclaration<RouterTestingModule, never>;
  44. static ɵmod: i0.ɵɵNgModuleDeclaration<RouterTestingModule, never, never, [typeof _angular_router.RouterModule]>;
  45. static ɵinj: i0.ɵɵInjectorDeclaration<RouterTestingModule>;
  46. }
  47. /**
  48. * A testing harness for the `Router` to reduce the boilerplate needed to test routes and routed
  49. * components.
  50. *
  51. * @publicApi
  52. */
  53. declare class RouterTestingHarness {
  54. /**
  55. * Creates a `RouterTestingHarness` instance.
  56. *
  57. * The `RouterTestingHarness` also creates its own root component with a `RouterOutlet` for the
  58. * purposes of rendering route components.
  59. *
  60. * Throws an error if an instance has already been created.
  61. * Use of this harness also requires `destroyAfterEach: true` in the `ModuleTeardownOptions`
  62. *
  63. * @param initialUrl The target of navigation to trigger before returning the harness.
  64. */
  65. static create(initialUrl?: string): Promise<RouterTestingHarness>;
  66. /**
  67. * Fixture of the root component of the RouterTestingHarness
  68. */
  69. readonly fixture: ComponentFixture<{
  70. routerOutletData: WritableSignal<unknown>;
  71. }>;
  72. /** Instructs the root fixture to run change detection. */
  73. detectChanges(): void;
  74. /** The `DebugElement` of the `RouterOutlet` component. `null` if the outlet is not activated. */
  75. get routeDebugElement(): DebugElement | null;
  76. /** The native element of the `RouterOutlet` component. `null` if the outlet is not activated. */
  77. get routeNativeElement(): HTMLElement | null;
  78. /**
  79. * Triggers a `Router` navigation and waits for it to complete.
  80. *
  81. * The root component with a `RouterOutlet` created for the harness is used to render `Route`
  82. * components. The root component is reused within the same test in subsequent calls to
  83. * `navigateForTest`.
  84. *
  85. * When testing `Routes` with a guards that reject the navigation, the `RouterOutlet` might not be
  86. * activated and the `activatedComponent` may be `null`.
  87. *
  88. * {@example router/testing/test/router_testing_harness_examples.spec.ts region='Guard'}
  89. *
  90. * @param url The target of the navigation. Passed to `Router.navigateByUrl`.
  91. * @returns The activated component instance of the `RouterOutlet` after navigation completes
  92. * (`null` if the outlet does not get activated).
  93. */
  94. navigateByUrl(url: string): Promise<null | {}>;
  95. /**
  96. * Triggers a router navigation and waits for it to complete.
  97. *
  98. * The root component with a `RouterOutlet` created for the harness is used to render `Route`
  99. * components.
  100. *
  101. * {@example router/testing/test/router_testing_harness_examples.spec.ts region='RoutedComponent'}
  102. *
  103. * The root component is reused within the same test in subsequent calls to `navigateByUrl`.
  104. *
  105. * This function also makes it easier to test components that depend on `ActivatedRoute` data.
  106. *
  107. * {@example router/testing/test/router_testing_harness_examples.spec.ts region='ActivatedRoute'}
  108. *
  109. * @param url The target of the navigation. Passed to `Router.navigateByUrl`.
  110. * @param requiredRoutedComponentType After navigation completes, the required type for the
  111. * activated component of the `RouterOutlet`. If the outlet is not activated or a different
  112. * component is activated, this function will throw an error.
  113. * @returns The activated component instance of the `RouterOutlet` after navigation completes.
  114. */
  115. navigateByUrl<T>(url: string, requiredRoutedComponentType: Type<T>): Promise<T>;
  116. }
  117. export { RouterTestingHarness, RouterTestingModule };