-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsetupTests.tsx
80 lines (72 loc) · 1.66 KB
/
setupTests.tsx
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// setup file
import React from 'react';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import '@testing-library/jest-dom';
configure({ adapter: new Adapter() });
// ymmv list of camel-cased attributes React supports for dom elements.
// https://reactjs.org/docs/dom-elements.html
const domAttributes = [
'acceptCharset',
'accessKey',
'allowFullScreen',
'autoComplete',
'autoFocus',
'autoPlay',
'cellPadding',
'cellSpacing',
'charSet',
'classID',
'className',
'colSpan',
'contentEditable',
'contextMenu',
'controlsList',
'crossOrigin',
'dateTime',
'encType',
'formAction',
'formEncType',
'formMethod',
'formNoValidate',
'formTarget',
'frameBorder',
'hrefLang',
'htmlFor',
'httpEquiv',
'inputMode',
'keyParams',
'keyType',
'marginHeight',
'marginWidth',
'maxLength',
'mediaGroup',
'minLength',
'noValidate',
'radioGroup',
'readOnly',
'rowSpan',
'spellCheck',
'srcDoc',
'srcLang',
'srcSet',
'tabIndex',
'useMap',
];
// TestComponent is deliberately super permissive, so it can be used anywhere.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type TestComponentProps = { [key: string]: any };
export const TestComponent = (props: TestComponentProps) => {
// Don't pass down invalid attributes to <div> to avoid annoying warnings
const safeProps = Object.entries(props).reduce((result, [key, value]) => {
if (key.toLowerCase() === key || domAttributes.indexOf(key) >= 0) {
result[key] = value;
}
return result;
}, {});
return <div {...safeProps} />;
};
const setupTests = {
TestComponent,
};
export default setupTests;