-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyledComponents.spec.tsx
62 lines (51 loc) · 1.62 KB
/
styledComponents.spec.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
import React from 'react';
import { render } from '@testing-library/react';
import { ServerStyleSheet } from 'styled-components';
import Headline from './fixtures/Headline';
import { getRealStyles } from '../index';
function getCss(sheet: ServerStyleSheet) {
return sheet
.getStyleElement()
.map(({ props }: any) => props.dangerouslySetInnerHTML.__html)
.join('\n');
}
describe('testing styled components', () => {
const sheet = new ServerStyleSheet();
it('works', async () => {
const { container, getByRole } = render(
sheet.collectStyles(<Headline>Hello</Headline>),
);
const styles = await getRealStyles({
css: getCss(sheet),
doc: container,
element: getByRole('heading'),
getStyles: ['backgroundColor'],
});
expect(styles).toEqual({ backgroundColor: 'fuchsia' });
});
it('works with props', async () => {
const { container, getByRole } = render(
sheet.collectStyles(<Headline blue>Hello</Headline>),
);
const styles = await getRealStyles({
css: getCss(sheet),
doc: container,
element: getByRole('heading'),
getStyles: ['backgroundColor'],
});
expect(styles).toEqual({ backgroundColor: 'blue' });
});
it('works with hover', async () => {
const { container, getByRole } = render(
sheet.collectStyles(<Headline>Hello</Headline>),
);
const styles = await getRealStyles({
css: getCss(sheet),
doc: container,
element: getByRole('heading'),
hover: getByRole('heading'),
getStyles: ['backgroundColor'],
});
expect(styles).toEqual({ backgroundColor: 'red' });
});
});