-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathsignals.spec.ts
More file actions
66 lines (58 loc) · 2.41 KB
/
signals.spec.ts
File metadata and controls
66 lines (58 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (c) 2024, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { describe, beforeEach, expect, it, vi } from 'vitest';
describe('signals', () => {
let setTrustedSignalSet: (signals: WeakSet<object>) => void;
let addTrustedSignal: (signal: object) => void;
let isTrustedSignal: (target: object) => boolean;
let legacyIsTrustedSignal: (target: object) => boolean;
beforeEach(async () => {
vi.resetModules();
const signalsModule = await import('../signals');
setTrustedSignalSet = signalsModule.setTrustedSignalSet;
addTrustedSignal = signalsModule.addTrustedSignal;
isTrustedSignal = signalsModule.isTrustedSignal;
legacyIsTrustedSignal = signalsModule.legacyIsTrustedSignal;
});
describe('setTrustedSignalSet', () => {
it('should throw an error if trustedSignals is already set', () => {
setTrustedSignalSet(new WeakSet());
expect(() => setTrustedSignalSet(new WeakSet())).toThrow(
'Trusted Signal Set is already set!'
);
});
});
describe('addTrustedSignal', () => {
it('should add a signal to the trustedSignals set', () => {
const mockWeakSet = new WeakSet();
setTrustedSignalSet(mockWeakSet);
const signal = {};
addTrustedSignal(signal);
expect(isTrustedSignal(signal)).toBe(true);
});
});
describe('isTrustedSignal', () => {
it('should return true for a trusted signal', () => {
const mockWeakSet = new WeakSet();
setTrustedSignalSet(mockWeakSet);
const signal = {};
addTrustedSignal(signal);
expect(isTrustedSignal(signal)).toBe(true);
});
it('should return false for an untrusted signal', () => {
const mockWeakSet = new WeakSet();
setTrustedSignalSet(mockWeakSet);
expect(isTrustedSignal({})).toBe(false);
});
it('should return false for all calls when trustedSignals is not set', () => {
expect(isTrustedSignal({})).toBe(false);
});
it('legacyIsTrustedSignal should return true when trustedSignals is not set', () => {
expect(legacyIsTrustedSignal({})).toBe(true);
});
});
});