Skip to content

Commit 3b61b5e

Browse files
fix: add global test fn for signals
1 parent 7a0fccf commit 3b61b5e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/@lwc/shared/src/signals.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
*/
77
import { isFalse } from './assert';
88

9-
let trustedSignals: WeakSet<object>;
9+
let trustedSignals: WeakSet<object> | undefined;
1010

1111
export function setTrustedSignalSet(signals: WeakSet<object>) {
1212
isFalse(trustedSignals, 'Trusted Signal Set is already set!');
1313

1414
trustedSignals = signals;
15+
16+
// Only used in LWC's Karma. Contained within the set function as there are multiple imports of
17+
// this module. Placing it here ensures we reference the import where the trustedSignals set is maintained
18+
if (process.env.NODE_ENV === 'test-karma-lwc') {
19+
// Used to reset the global state between test runs
20+
(globalThis as any).__lwcResetTrustedSignalsSetForTest = () => (trustedSignals = undefined);
21+
}
1522
}
1623

1724
export function addTrustedSignal(signal: object) {

0 commit comments

Comments
 (0)