index.d.ts 5.4 KB

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