|
1 | | -import { expect } from '@jest/globals'; |
| 1 | +import { expect, jest } from '@jest/globals'; |
2 | 2 | import { scenario } from '@testduet/given-when-then'; |
3 | 3 | import Graph from './Graph'; |
4 | 4 | import './schemas/private/expectExtendValibot'; |
@@ -36,24 +36,26 @@ scenario('Graph.upsert()', bdd => { |
36 | 36 | ); |
37 | 37 |
|
38 | 38 | bdd |
39 | | - .given( |
40 | | - 'a Graph object', |
41 | | - () => new Graph<{ readonly '@id': Identifier; readonly name: string }>(() => () => request => request) |
42 | | - ) |
43 | | - .when('act().upsert() is called twice with node of same @id', graph => { |
44 | | - try { |
45 | | - graph.act(graph => graph.upsert({ '@id': '_:b1', name: 'John Doe' }, { '@id': '_:b1', name: 'Mary Doe' })); |
46 | | - } catch (error) { |
47 | | - return error; |
48 | | - } |
| 39 | + .given('a Graph object', () => ({ |
| 40 | + graph: new Graph<{ readonly '@id': Identifier; readonly name: string }>(() => () => request => request) |
| 41 | + })) |
| 42 | + .and( |
| 43 | + 'spying console.warn()', |
| 44 | + precondition => { |
| 45 | + const warn = jest.spyOn(console, 'warn'); |
49 | 46 |
|
50 | | - return undefined; |
| 47 | + return { ...precondition, warn }; |
| 48 | + }, |
| 49 | + ({ warn }) => { |
| 50 | + warn.mockRestore(); |
| 51 | + } |
| 52 | + ) |
| 53 | + .when('act().upsert() is called twice with node of same @id', ({ graph }) => { |
| 54 | + graph.act(graph => graph.upsert({ '@id': '_:b1', name: 'John Doe' }, { '@id': '_:b1', name: 'Mary Doe' })); |
51 | 55 | }) |
52 | | - .then('should throw', (_, error) => { |
53 | | - expect(() => { |
54 | | - if (error) { |
55 | | - throw error; |
56 | | - } |
57 | | - }).toThrow('Cannot upsert a node multiple times in a single transaction (@id = "_:b1")'); |
| 56 | + .then('should throw', ({ warn }) => { |
| 57 | + expect(warn).toHaveBeenCalledWith( |
| 58 | + 'botframework-webchat: Should NOT upsert a node multiple times in a single transaction (@id = "_:b1")' |
| 59 | + ); |
58 | 60 | }); |
59 | 61 | }); |
0 commit comments