forked from ant-design/cssinjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer.spec.tsx
99 lines (90 loc) · 2.22 KB
/
layer.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { render } from '@testing-library/react';
import React from 'react';
import { createCache, createTheme, StyleProvider } from '../src';
import useStyleRegister from '../src/hooks/useStyleRegister';
vi.mock('../src/util', async () => {
const origin: any = await vi.importActual('../src/util');
return {
...origin,
supportLayer: () => true,
};
});
describe('layer', () => {
beforeEach(() => {
// Clear header
document.head.innerHTML = '';
});
it('order', () => {
const theme = createTheme(() => ({}));
const Demo = () => {
// Button
useStyleRegister(
{
theme,
token: { _tokenKey: 'test' },
path: ['button'],
layer: {
name: 'button',
dependencies: ['shared'],
},
},
() => ({
p: {
color: 'red',
},
}),
);
// Shared
useStyleRegister(
{
theme,
token: { _tokenKey: 'test' },
path: ['shared'],
layer: {
name: 'shared',
},
},
() => ({
p: {
color: 'red',
},
}),
);
return null;
};
render(
<StyleProvider layer cache={createCache()}>
<Demo />
</StyleProvider>,
);
const styles = Array.from(document.head.querySelectorAll('style'));
expect(styles[0].innerHTML.trim()).toEqual('@layer shared,button;');
});
// TODO: try fix, If stylis is fixed, this case should not be needed here.
// https://github.com/thysultan/stylis/pull/339
// https://github.com/ant-design/ant-design/issues/51867
it('empty braces (#51867)', () => {
const theme = createTheme(() => ({}));
const Demo = () => {
useStyleRegister(
{
theme,
token: { _tokenKey: 'test' },
path: ['shared'],
layer: {
name: 'shared',
},
},
() => [],
);
return null;
};
render(
<StyleProvider layer cache={createCache()}>
<Demo />
</StyleProvider>,
);
const styles = Array.from(document.head.querySelectorAll('style'));
expect(styles[0].innerHTML.trim()).toEqual('');
});
});