@@ -2,7 +2,7 @@ import { createGlobalStyle, isStyledComponent, styled } from '../index'
22import { afterEach , describe , expect , it } from 'vitest'
33import { render , cleanup } from '@testing-library/vue'
44import { getStyle } from './utils'
5- import { ref } from 'vue'
5+ import { h , ref } from 'vue'
66
77describe ( 'styled' , ( ) => {
88 afterEach ( ( ) => {
@@ -72,8 +72,10 @@ describe('styled', () => {
7272 it ( 'should inject attrs' , async ( ) => {
7373 const StyledComponent = styled . div . attrs ( {
7474 'data-testid' : 'test' ,
75+ color : 'rgb(0, 0, 255)' ,
7576 } ) `
7677 height: 36px;
78+ color: ${ ( props ) => props . color } ;
7779 `
7880 const instance = render ( StyledComponent )
7981 const element = instance . getByTestId ( 'test' )
@@ -83,6 +85,24 @@ describe('styled', () => {
8385
8486 const style = getStyle ( element )
8587 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)' )
86106 } )
87107
88108 it ( 'should react to props change' , async ( ) => {
@@ -118,4 +138,21 @@ describe('styled', () => {
118138 const style = getStyle ( instance . baseElement )
119139 expect ( style ?. background ) . toBe ( 'rgb(255, 0, 0)' )
120140 } )
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+ } )
121158} )
0 commit comments