-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathto-be-expanded.ts
More file actions
41 lines (36 loc) · 1.26 KB
/
to-be-expanded.ts
File metadata and controls
41 lines (36 loc) · 1.26 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
import { matcherHint } from 'jest-matcher-utils';
import redent from 'redent';
import type { HostElement } from 'test-renderer';
import { computeAriaExpanded } from '../helpers/accessibility';
import { formatElement } from '../helpers/format-element';
import { checkHostElement } from './utils';
export function toBeExpanded(this: jest.MatcherContext, element: HostElement) {
checkHostElement(element, toBeExpanded, this);
return {
pass: computeAriaExpanded(element) === true,
message: () => {
const matcher = matcherHint(`${this.isNot ? '.not' : ''}.toBeExpanded`, 'element', '');
return [
matcher,
'',
`Received element is ${this.isNot ? '' : 'not '}expanded:`,
redent(formatElement(element), 2),
].join('\n');
},
};
}
export function toBeCollapsed(this: jest.MatcherContext, element: HostElement) {
checkHostElement(element, toBeCollapsed, this);
return {
pass: computeAriaExpanded(element) === false,
message: () => {
const matcher = matcherHint(`${this.isNot ? '.not' : ''}.toBeCollapsed`, 'element', '');
return [
matcher,
'',
`Received element is ${this.isNot ? '' : 'not '}collapsed:`,
redent(formatElement(element), 2),
].join('\n');
},
};
}