-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
to-be-empty-object.ts
32 lines (29 loc) · 1010 Bytes
/
to-be-empty-object.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
import { isEmptyObject } from 'expect-more';
import { createResult } from './lib/create-result';
declare global {
namespace jest {
interface Expect {
/**
* Asserts that a value is a valid `Object` containing no members.
* @example
* expect(onPress).toHaveBeenCalledWith(expect.objectContaining({ byId: expect.toBeEmptyObject() }));
*/
toBeEmptyObject<T>(): JestMatchers<T>;
}
interface Matchers<R, T> {
/**
* Asserts that a value is a valid `Object` containing no members.
* @example
* expect(openIssues.byId).toBeEmptyObject();
*/
toBeEmptyObject(): R;
}
}
}
export const toBeEmptyObjectMatcher = (received: any) =>
createResult({
message: () => `expected ${received} to be an object without any own members`,
notMessage: () => `expected ${received} not to be an object without any own members`,
pass: isEmptyObject(received)
});
expect.extend({ toBeEmptyObject: toBeEmptyObjectMatcher });