forked from elastic/eui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flex_item.test.js
69 lines (57 loc) · 1.61 KB
/
flex_item.test.js
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
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';
import { EuiFlexItem } from './flex_item';
const consoleWarn = console.warn;
const consoleError = console.error;
beforeAll(() => {
console.warn = console.error = (msg) => { throw msg; };
});
afterAll(() => {
console.warn = consoleWarn;
console.error = consoleError;
});
describe('EuiFlexItem', () => {
test('is rendered', () => {
const component = render(
<EuiFlexItem {...requiredProps} />
);
expect(component)
.toMatchSnapshot();
});
test('tests the grow prop correctly', () => {
const propType = EuiFlexItem.propTypes.grow;
const validValues = [undefined, null, true, false, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const invalidValues = ['true', 'false', '1', 0];
validValues.forEach(value =>
expect(propType({ grow: value }, `grow`)).toBe(undefined)
);
invalidValues.forEach(value =>
expect(propType({ grow: value }, `grow`) instanceof Error).toBe(true)
);
});
describe('component', () => {
['div', 'span'].forEach(value => {
test(`${value} is rendered`, () => {
const component = render(
<EuiFlexItem
component={value}
{...requiredProps}
/>
);
expect(component)
.toMatchSnapshot();
});
});
['h2'].forEach(value => {
test(`${value} is not rendered`, () => {
expect(() => render(
<EuiFlexItem
component={value}
{...requiredProps}
/>
)).toThrow();
});
});
});
});