testing.mjs 4.4 KB

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