-
Notifications
You must be signed in to change notification settings - Fork 2
/
map-and-set.spec.ts
43 lines (40 loc) · 1.05 KB
/
map-and-set.spec.ts
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
import { inspect } from 'util';
import { describe, expect, test } from 'vitest';
import { capture, manage } from '../src';
describe('map and set', () => {
test('map', () => {
class A {
public m = new Map<string, number>();
}
const a = new A();
const ma = manage(a);
ma.m.set('a', 1);
expect(ma.m.get('a')).toBe(1);
expect(ma.m.has('a')).toBe(true);
});
test('set', () => {
class A {
public s = new Set<string>();
}
const a = new A();
const ma = manage(a);
ma.s.add('a');
expect(ma.s.has('a')).toBe(true);
});
test('traps', () => {
class A {
public m = new Map<string, number>();
}
const a = new A();
const ma = manage(a);
ma.m.set('a', 1);
const [, readLogs] = capture(() => {
expect(ma.m.get('a')).toBe(1);
expect(ma.m.has('a')).toBe(true);
});
expect(inspect(readLogs)).toBe(`Map(2) {
A { m: Map(1) { 'a' => 1 } } => { get: Map(1) { 'm' => [Map] } },
Map(1) { 'a' => 1 } => { get: Map(1) { 'a' => 1 }, has: Map(1) { 'a' => true } }
}`);
});
});