-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathGraph.act.spec.ts
More file actions
54 lines (48 loc) · 1.58 KB
/
Graph.act.spec.ts
File metadata and controls
54 lines (48 loc) · 1.58 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
import { expect } from '@jest/globals';
import { scenario } from '@testduet/given-when-then';
import { assert, object } from 'valibot';
import Graph from './Graph';
import './schemas/private/expectExtendValibot';
import './schemas/private/expectIsFrozen';
scenario('Graph.act()', bdd => {
bdd
.given('a Graph object', () => new Graph(() => () => request => request))
.when('act() is called twice nested', graph => {
try {
graph.act(() => {
graph.act(() => {
// Intentionally left blank.
});
});
} catch (error) {
return { error };
}
return {};
})
.then('should throw', (_, { error }) => {
// Because the writable graph does not support parallel writes.
expect(() => {
if (error) {
throw error;
}
}).toThrow('Another transaction is ongoing');
});
bdd
.given('a Graph object', () => new Graph(() => () => request => request))
.when('act() is called', graph => {
let writableGraph;
graph.act(graph => {
writableGraph = graph;
});
assert(object({}), writableGraph);
return writableGraph;
})
.then('the writableGraph argument should not have act', (_, writableGraph) =>
// Because the writable graph does not support writes in a nested manner.
expect('act' in writableGraph).toBe(false)
)
.and('the writableGraph argument should not have subscribe', (_, writableGraph) =>
// Because the writable graph should be short-lived.
expect('subscribe' in writableGraph).toBe(false)
);
});