@jscutlery/playwright-ct-angular 0.6.4 → 0.7.0

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/README.md CHANGED
@@ -281,7 +281,7 @@ Cf. https://youtu.be/y3YxX4sFJbM
281
281
 
282
282
  Cf. https://github.com/microsoft/playwright/blob/cac67fb94f2c8a0ee82878054c39790e660f17ca/packages/playwright-test/src/tsxTransform.ts#L153
283
283
 
284
- ###
284
+ ###
285
285
 
286
286
  # 📦 Setup
287
287
 
@@ -347,3 +347,34 @@ const config: PlaywrightTestConfig = {
347
347
  ...
348
348
  }
349
349
  ```
350
+
351
+ ### 4. Choose between zoneful or zoneless testing
352
+
353
+ #### Zoneful Testing
354
+
355
+ If you want to use zoneful testing, you have to import `zone.js` in your `playwright/index.ts`:
356
+
357
+ ```ts
358
+ // playwright/index.ts
359
+ import 'zone.js';
360
+ ```
361
+
362
+ #### Zoneless Testing
363
+
364
+ For zoneless testing, you have to provide `provideExperimentalZonelessChangeDetection()` in your `playwright/index.ts`:
365
+
366
+ ```ts
367
+ // playwright/index.ts
368
+ import { provideExperimentalZonelessChangeDetection } from '@angular/core';
369
+ import { beforeMount } from '@jscutlery/playwright-ct-angular/hooks';
370
+
371
+ beforeMount(async ({ TestBed }) => {
372
+ TestBed.configureTestingModule({
373
+ providers: [
374
+ provideExperimentalZonelessChangeDetection(),
375
+ ],
376
+ });
377
+ });
378
+ ```
379
+
380
+ Cf. [Zoneless Example's `playwright/index.ts`](../../tests/playwright-ct-angular-demo/playwright/index.ts)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jscutlery/playwright-ct-angular",
3
- "version": "0.6.4",
3
+ "version": "0.7.0",
4
4
  "dependencies": {
5
5
  "@babel/core": "7.23.9",
6
6
  "@playwright/experimental-ct-core": "1.43.1",
@@ -37,4 +37,4 @@
37
37
  },
38
38
  "module": "./index.esm.js",
39
39
  "main": "./index.cjs.js"
40
- }
40
+ }
@@ -1,10 +1,7 @@
1
- import '@angular/compiler';
2
- import 'zone.js';
3
-
4
- import { getTestBed, TestBed, TestComponentRenderer } from '@angular/core/testing';
1
+ import { Component, reflectComponentType } from '@angular/core';
2
+ import { ComponentFixtureAutoDetect, getTestBed, TestBed, TestComponentRenderer } from '@angular/core/testing';
5
3
  import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
6
4
  import { Subscription } from 'rxjs';
7
- import { Component, reflectComponentType } from '@angular/core';
8
5
 
9
6
  /**
10
7
  * @typedef {{type: string} & import('./index').MountTemplateOptions} TemplateInfo
@@ -22,9 +19,6 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
22
19
 
23
20
  const fixture = await __pwRenderComponent(component, rootElement);
24
21
 
25
- fixture.autoDetectChanges();
26
- await fixture.whenStable();
27
-
28
22
  for (const hook of window.__pw_hooks_after_mount || [])
29
23
  await hook({ hooksConfig });
30
24
 
@@ -56,7 +50,6 @@ window.playwrightUpdate = async (rootElement, component) => {
56
50
  __pwUpdateProps(fixture, component);
57
51
  __pwUpdateEvents(fixture, component.on);
58
52
 
59
- fixture.autoDetectChanges();
60
53
  await fixture.whenStable();
61
54
  };
62
55
 
@@ -94,6 +87,7 @@ async function __pwRenderComponent(component, rootElement) {
94
87
  TestBed.configureTestingModule({
95
88
  imports: [componentClass],
96
89
  providers: [
90
+ { provide: ComponentFixtureAutoDetect, useValue: true },
97
91
  {
98
92
  provide: TestComponentRenderer,
99
93
  useValue: new PlaywrightTestComponentRenderer(rootElement)
@@ -106,6 +100,8 @@ async function __pwRenderComponent(component, rootElement) {
106
100
  __pwUpdateProps(fixture, component);
107
101
  __pwUpdateEvents(fixture, component.on);
108
102
 
103
+ await fixture.whenStable();
104
+
109
105
  return fixture;
110
106
  }
111
107
 
@@ -119,6 +115,7 @@ function __pwUpdateProps(fixture, componentInfo) {
119
115
 
120
116
  if (__pwIsTemplate(componentInfo)) {
121
117
  Object.assign(fixture.componentInstance, componentInfo.props);
118
+ fixture.detectChanges();
122
119
  } else {
123
120
  for (const [name, value] of Object.entries(componentInfo.props))
124
121
  fixture.componentRef.setInput(name, value);