@@ -3,6 +3,7 @@ import { render, renderHook } from '@testing-library/react';
3
3
4
4
import { genStyleUtils } from '../src' ;
5
5
import type { CSSVarRegisterProps , SubStyleComponentProps } from '../src/util/genStyleUtils' ;
6
+ import { createCache , StyleProvider } from '@ant-design/cssinjs' ;
6
7
7
8
interface TestCompTokenMap {
8
9
TestComponent : object ;
@@ -23,6 +24,10 @@ describe('genStyleUtils', () => {
23
24
} ) ,
24
25
useCSP : jest . fn ( ) . mockReturnValue ( { nonce : 'nonce' } ) ,
25
26
getResetStyles : jest . fn ( ) . mockReturnValue ( [ ] ) ,
27
+ layer : {
28
+ name : 'test' ,
29
+ dependencies : [ 'parent' ] ,
30
+ } ,
26
31
} ;
27
32
28
33
const { genStyleHooks, genSubStyleComponent, genComponentStyleHook } = genStyleUtils <
@@ -31,6 +36,12 @@ describe('genStyleUtils', () => {
31
36
object
32
37
> ( mockConfig ) ;
33
38
39
+ beforeEach ( ( ) => {
40
+ // Clear head style
41
+ const head = document . head ;
42
+ head . innerHTML = '' ;
43
+ } ) ;
44
+
34
45
describe ( 'genStyleHooks' , ( ) => {
35
46
it ( 'should generate style hooks' , ( ) => {
36
47
const component = 'TestComponent' ;
@@ -89,4 +100,20 @@ describe('genStyleUtils', () => {
89
100
expect ( getByTestId ( 'test-root' ) ) . toHaveTextContent ( 'test-prefix' ) ;
90
101
} ) ;
91
102
} ) ;
103
+
104
+ it ( 'layer' , ( ) => {
105
+ const StyledComponent = genSubStyleComponent (
106
+ 'TestComponent' ,
107
+ ( ) => ( { } ) ,
108
+ ( ) => ( { } ) ,
109
+ ) ;
110
+
111
+ render (
112
+ < StyleProvider cache = { createCache ( ) } layer >
113
+ < StyledComponent prefixCls = "test" />
114
+ </ StyleProvider > ,
115
+ ) ;
116
+
117
+ expect ( document . head . innerHTML ) . toContain ( '@layer parent,test;' ) ;
118
+ } ) ;
92
119
} ) ;
0 commit comments