@jscutlery/playwright-ct-angular 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jscutlery/playwright-ct-angular",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "dependencies": {
5
5
  "@babel/core": "7.23.9",
6
6
  "@playwright/experimental-ct-core": "1.43.1",
@@ -1,7 +1,7 @@
1
1
  import '@angular/compiler';
2
2
  import 'zone.js';
3
3
 
4
- import { getTestBed, TestBed } from '@angular/core/testing';
4
+ import { getTestBed, TestBed, TestComponentRenderer } from '@angular/core/testing';
5
5
  import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
6
6
  import { Subscription } from 'rxjs';
7
7
  import { Component, reflectComponentType } from '@angular/core';
@@ -20,7 +20,7 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
20
20
  for (const hook of window.__pw_hooks_before_mount || [])
21
21
  await hook({ hooksConfig, TestBed });
22
22
 
23
- const fixture = await __pwRenderComponent(component);
23
+ const fixture = await __pwRenderComponent(component, rootElement);
24
24
 
25
25
  fixture.autoDetectChanges();
26
26
  await fixture.whenStable();
@@ -68,8 +68,9 @@ const __pwFixtureRegistry = new Map();
68
68
 
69
69
  /**
70
70
  * @param {ComponentInfo} component
71
+ * @param {Element} rootElement
71
72
  */
72
- async function __pwRenderComponent(component) {
73
+ async function __pwRenderComponent(component, rootElement) {
73
74
  /** @type {import('@angular/core').Type<unknown>} */
74
75
  let componentClass;
75
76
 
@@ -92,12 +93,16 @@ async function __pwRenderComponent(component) {
92
93
 
93
94
  TestBed.configureTestingModule({
94
95
  imports: [componentClass],
95
- providers: component.providers
96
+ providers: [
97
+ {
98
+ provide: TestComponentRenderer,
99
+ useValue: new PlaywrightTestComponentRenderer(rootElement)
100
+ },
101
+ ...component.providers ?? []
102
+ ]
96
103
  });
97
104
 
98
105
  const fixture = TestBed.createComponent(componentClass);
99
- fixture.nativeElement.id = 'root';
100
-
101
106
  __pwUpdateProps(fixture, component);
102
107
  __pwUpdateEvents(fixture, component.on);
103
108
 
@@ -146,3 +151,24 @@ function __pwUpdateEvents(fixture, events = {}) {
146
151
  function __pwIsTemplate(component) {
147
152
  return typeof component.type === 'string';
148
153
  }
154
+
155
+ class PlaywrightTestComponentRenderer extends TestComponentRenderer {
156
+
157
+ constructor(rootElement) {
158
+ super();
159
+ this._children = [];
160
+ this._rootElement = rootElement;
161
+ }
162
+
163
+ insertRootElement(testRootElementId) {
164
+ const testRootElement = document.createElement('div');
165
+ testRootElement.id = testRootElementId;
166
+ this._rootElement.appendChild(testRootElement);
167
+ }
168
+
169
+ removeAllRootElements() {
170
+ for (const child of this._children)
171
+ this._rootElement.removeChild(child);
172
+ this._children = [];
173
+ }
174
+ }