@@ -2,7 +2,7 @@ import { createGlobalStyle, isStyledComponent, styled } from '../index'
2
2
import { afterEach , describe , expect , it } from 'vitest'
3
3
import { render , cleanup } from '@testing-library/vue'
4
4
import { getStyle } from './utils'
5
- import { ref } from 'vue'
5
+ import { h , ref } from 'vue'
6
6
7
7
describe ( 'styled' , ( ) => {
8
8
afterEach ( ( ) => {
@@ -72,8 +72,10 @@ describe('styled', () => {
72
72
it ( 'should inject attrs' , async ( ) => {
73
73
const StyledComponent = styled . div . attrs ( {
74
74
'data-testid' : 'test' ,
75
+ color : 'rgb(0, 0, 255)' ,
75
76
} ) `
76
77
height: 36px;
78
+ color: ${ ( props ) => props . color } ;
77
79
`
78
80
const instance = render ( StyledComponent )
79
81
const element = instance . getByTestId ( 'test' )
@@ -83,6 +85,24 @@ describe('styled', () => {
83
85
84
86
const style = getStyle ( element )
85
87
expect ( style ?. height ) . eq ( '36px' )
88
+ expect ( style ?. color ) . eq ( 'rgb(0, 0, 255)' )
89
+
90
+ const StyledComponent2 = styled . div . attrs ( ( ) => ( {
91
+ 'data-testid' : 'test2' ,
92
+ color : 'rgb(255, 0, 0)' ,
93
+ } ) ) `
94
+ height: 36px;
95
+ color: ${ ( props ) => props . color } ;
96
+ `
97
+ const instance2 = render ( StyledComponent2 )
98
+ const element2 = instance2 . getByTestId ( 'test2' )
99
+
100
+ expect ( element2 ) . toBeDefined ( )
101
+ expect ( element2 . dataset [ 'testid' ] ) . eq ( 'test2' )
102
+
103
+ const style2 = getStyle ( element2 )
104
+ expect ( style2 ?. height ) . eq ( '36px' )
105
+ expect ( style2 ?. color ) . eq ( 'rgb(255, 0, 0)' )
86
106
} )
87
107
88
108
it ( 'should react to props change' , async ( ) => {
@@ -118,4 +138,21 @@ describe('styled', () => {
118
138
const style = getStyle ( instance . baseElement )
119
139
expect ( style ?. background ) . toBe ( 'rgb(255, 0, 0)' )
120
140
} )
141
+
142
+ it ( 'should take effect of using styled component as selector' , async ( ) => {
143
+ const StyledComponent = styled ( 'div' , { color : String } ) . attrs ( { 'data-testid' : 'test' } ) ``
144
+ const Container = styled . div `
145
+ ${ StyledComponent } {
146
+ height: 20px;
147
+ }
148
+ `
149
+ const instance = render ( Container , {
150
+ slots : {
151
+ default : ( ) => h ( StyledComponent ) ,
152
+ } ,
153
+ } )
154
+ const element = instance . getByTestId ( 'test' )
155
+ const style = getStyle ( element )
156
+ expect ( style ?. height ) . toBe ( '20px' )
157
+ } )
121
158
} )
0 commit comments