forked from opensearch-project/dashboards-observability
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_expects.ts
37 lines (35 loc) · 1013 Bytes
/
custom_expects.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
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Useful for asserting results are okay, while still having access to error information. A context
* object can be supplied to help provide context if the value of the result doesn't contain enough
* information to know what went wrong.
*/
export const expectOkResult = (result: Result<unknown>, context?: string | object) => {
const labeled = {
...result,
context,
};
expect(labeled).toEqual({
ok: true,
context,
value: expect.anything(),
});
};
/**
* Validate an error result is correctly returned. A context object can be supplied to help provide
* context if the value of the result doesn't contain enough information to know what went wrong.
*/
export const expectErrorResult = (result: Result<unknown>, context?: string | object) => {
const labeled = {
...result,
context,
};
expect(labeled).toEqual({
ok: false,
context,
error: expect.anything(),
});
};