index.d.ts 5.2 KB

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