testing.mjs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * @license Angular v19.2.13
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import { ɵgetDOM as _getDOM, DOCUMENT, PlatformLocation } from '@angular/common';
  7. import { MockPlatformLocation } from '@angular/common/testing';
  8. import * as i0 from '@angular/core';
  9. import { Inject, Injectable, createPlatformFactory, APP_ID, ɵinternalProvideZoneChangeDetection as _internalProvideZoneChangeDetection, ɵChangeDetectionSchedulerImpl as _ChangeDetectionSchedulerImpl, ɵChangeDetectionScheduler as _ChangeDetectionScheduler, NgModule } from '@angular/core';
  10. import { TestComponentRenderer } from '@angular/core/testing';
  11. import { platformBrowser, BrowserModule } from './browser-D-u-fknz.mjs';
  12. import './dom_renderer-DGKzginR.mjs';
  13. /**
  14. * A DOM based implementation of the TestComponentRenderer.
  15. */
  16. class DOMTestComponentRenderer extends TestComponentRenderer {
  17. _doc;
  18. constructor(_doc) {
  19. super();
  20. this._doc = _doc;
  21. }
  22. insertRootElement(rootElId) {
  23. this.removeAllRootElementsImpl();
  24. const rootElement = _getDOM().getDefaultDocument().createElement('div');
  25. rootElement.setAttribute('id', rootElId);
  26. this._doc.body.appendChild(rootElement);
  27. }
  28. removeAllRootElements() {
  29. // Check whether the `DOCUMENT` instance retrieved from DI contains
  30. // the necessary function to complete the cleanup. In tests that don't
  31. // interact with DOM, the `DOCUMENT` might be mocked and some functions
  32. // might be missing. For such tests, DOM cleanup is not required and
  33. // we skip the logic if there are missing functions.
  34. if (typeof this._doc.querySelectorAll === 'function') {
  35. this.removeAllRootElementsImpl();
  36. }
  37. }
  38. removeAllRootElementsImpl() {
  39. const oldRoots = this._doc.querySelectorAll('[id^=root]');
  40. for (let i = 0; i < oldRoots.length; i++) {
  41. _getDOM().remove(oldRoots[i]);
  42. }
  43. }
  44. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: DOMTestComponentRenderer, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
  45. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: DOMTestComponentRenderer });
  46. }
  47. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: DOMTestComponentRenderer, decorators: [{
  48. type: Injectable
  49. }], ctorParameters: () => [{ type: undefined, decorators: [{
  50. type: Inject,
  51. args: [DOCUMENT]
  52. }] }] });
  53. /**
  54. * Platform for testing
  55. *
  56. * @publicApi
  57. */
  58. const platformBrowserTesting = createPlatformFactory(platformBrowser, 'browserTesting');
  59. /**
  60. * NgModule for testing.
  61. *
  62. * @publicApi
  63. */
  64. class BrowserTestingModule {
  65. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: BrowserTestingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  66. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.13", ngImport: i0, type: BrowserTestingModule, exports: [BrowserModule] });
  67. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: BrowserTestingModule, providers: [
  68. { provide: APP_ID, useValue: 'a' },
  69. _internalProvideZoneChangeDetection({}),
  70. { provide: _ChangeDetectionScheduler, useExisting: _ChangeDetectionSchedulerImpl },
  71. { provide: PlatformLocation, useClass: MockPlatformLocation },
  72. { provide: TestComponentRenderer, useClass: DOMTestComponentRenderer },
  73. ], imports: [BrowserModule] });
  74. }
  75. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: BrowserTestingModule, decorators: [{
  76. type: NgModule,
  77. args: [{
  78. exports: [BrowserModule],
  79. providers: [
  80. { provide: APP_ID, useValue: 'a' },
  81. _internalProvideZoneChangeDetection({}),
  82. { provide: _ChangeDetectionScheduler, useExisting: _ChangeDetectionSchedulerImpl },
  83. { provide: PlatformLocation, useClass: MockPlatformLocation },
  84. { provide: TestComponentRenderer, useClass: DOMTestComponentRenderer },
  85. ],
  86. }]
  87. }] });
  88. export { BrowserTestingModule, platformBrowserTesting };
  89. //# sourceMappingURL=testing.mjs.map