@blotch/angular-lynx-testing-library 22.2.15 → 22.2.17

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
@@ -122,6 +122,8 @@ await waitForUpdate();
122
122
 
123
123
  Call this after any signal mutation that happens outside an event handler (e.g. direct `.set()` in test code).
124
124
 
125
+ Under `vi.useFakeTimers()`, change detection waits for the fake clock as well, so nothing renders on the real clock. `waitForUpdate()` waits on a zero-delay `setTimeout` then: start it, move the clock (`await vi.advanceTimersByTimeAsync(1)`), and await it.
126
+
125
127
  ### `fireEvent`
126
128
 
127
129
  Fires Lynx events at JSDOM elements. Use the named helpers for standard Lynx events:
package/dist/setup.js CHANGED
@@ -69,9 +69,30 @@ const returnOnWarnings = (threadGlobals) => {
69
69
  reportError(error, options);
70
70
  };
71
71
  };
72
- globalThis.onInjectMainThreadGlobals = returnOnWarnings;
72
+ /**
73
+ * Makes each thread's `requestAnimationFrame` wait on whichever `setTimeout`
74
+ * is installed when it's called, so `vi.useFakeTimers()` controls it too.
75
+ *
76
+ * The testing environment sets each thread's `requestAnimationFrame` to
77
+ * `setTimeout` itself, captured when the environment is created, before any
78
+ * test fakes the timers, and puts it back on the global at every thread
79
+ * switch. Angular schedules change detection with a race between a timer and
80
+ * an animation frame, so under fake timers a change detection still ran on
81
+ * the real clock whenever real time passed, wherever the fake clock was: a
82
+ * spec that moved the clock itself saw an update at an unpredictable moment.
83
+ * Like the environment's, a frame here waits for the next turn of the timers.
84
+ */
85
+ const frameOnInstalledTimers = (threadGlobals) => {
86
+ threadGlobals.requestAnimationFrame = (callback) => setTimeout(callback);
87
+ threadGlobals.cancelAnimationFrame = (id) => clearTimeout(id);
88
+ };
89
+ globalThis.onInjectMainThreadGlobals = (threadGlobals) => {
90
+ returnOnWarnings(threadGlobals);
91
+ frameOnInstalledTimers(threadGlobals);
92
+ };
73
93
  globalThis.onInjectBackgroundThreadGlobals = (threadGlobals) => {
74
94
  returnOnWarnings(threadGlobals);
95
+ frameOnInstalledTimers(threadGlobals);
75
96
  // LynxLinking records the URLs it opens (see linking.ts).
76
97
  installLinkingModule(threadGlobals);
77
98
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotch/angular-lynx-testing-library",
3
- "version": "22.2.15",
3
+ "version": "22.2.17",
4
4
  "description": "Testing utilities for AngularLynx apps",
5
5
  "homepage": "https://github.com/Blotch-Smart-Frames/AngularLynx#readme",
6
6
  "bugs": {