@@ -92,6 +92,61 @@ describe('createStyles', () => {
9292 } ) ;
9393 } ) ;
9494
95+ it ( '获取 antdPrefixCls,未通过ConfigProvider传入 prefixCls时,拿到的perfixCls应该为ant design默认的"ant"' , ( ) => {
96+ const useStyles = createStyles ( ( { css, antdPrefixCls } ) => {
97+ return {
98+ button : css `
99+ & .${ antdPrefixCls } -div {
100+ background : lightsteelblue;
101+ border : none;
102+ font-size : 10px ;
103+ }
104+ ` ,
105+ } ;
106+ } ) ;
107+
108+ const App = ( ) => {
109+ const { styles } = useStyles ( ) ;
110+
111+ return < div className = { `${ styles . button } ant-div` } > my custom button</ div > ;
112+ } ;
113+
114+ const { container } = render ( < App /> ) ;
115+ expect ( container . firstChild ) . toHaveClass ( 'ant-div' ) ;
116+ expect ( container . firstChild ) . toHaveStyle ( { fontSize : '10px' } ) ;
117+ } ) ;
118+
119+ it ( '获取 antdPrefixCls,通过ConfigProvider传入 prefixCls 时,拿到的值为传入的prefixCls' , ( ) => {
120+ const myCustomAntPrefix = 'my-custom-ant-prefix2' ;
121+ const useStyles = createStyles ( ( { css, antdPrefixCls } ) => {
122+ return {
123+ button : css `
124+ & .${ antdPrefixCls } -div {
125+ background : lightsteelblue;
126+ border : none;
127+ font-size : 11px ;
128+ }
129+ ` ,
130+ } ;
131+ } ) ;
132+
133+ const App = ( ) => {
134+ const { styles } = useStyles ( ) ;
135+
136+ return (
137+ < div className = { `${ styles . button } ${ `${ myCustomAntPrefix } -div` } ` } > my custom Button</ div >
138+ ) ;
139+ } ;
140+
141+ const wrapper = ( { children } : PropsWithChildren ) => (
142+ < ConfigProvider prefixCls = { myCustomAntPrefix } > { children } </ ConfigProvider >
143+ ) ;
144+
145+ const { container } = render ( < App /> , { wrapper } ) ;
146+ expect ( container . firstChild ) . toHaveClass ( `${ myCustomAntPrefix } -div` ) ;
147+ expect ( container . firstChild ) . toHaveStyle ( { fontSize : '11px' } ) ;
148+ } ) ;
149+
95150 describe ( 'styleObject 方法' , ( ) => {
96151 it ( '对象模式的用法' , ( ) => {
97152 const useStyles = createStyles ( {
0 commit comments