1- import { render , screen , within } from '@solidjs/testing-library' ;
1+ import { render , screen } from '@solidjs/testing-library' ;
22import { expect , describe , test , vi , beforeAll } from 'vitest' ;
3- import { mount } from '@vue/test-utils' ;
43import { HidingHeader } from '@/index' ;
54
65describe ( 'HidingHeader component' , ( ) => {
@@ -17,54 +16,57 @@ describe('HidingHeader component', () => {
1716 } ) ;
1817
1918 test ( 'should exists' , ( ) => {
20- const wrapper = mount ( HidingHeader )
21- expect ( wrapper ) . toBeTruthy ( )
19+ const { unmount } = render ( ( ) => < HidingHeader > Header</ HidingHeader > ) ;
20+ const element = screen . getByRole ( 'banner' ) ;
21+ expect ( element ) . toBeTruthy ( ) ;
22+ unmount ( ) ;
2223 } ) ;
2324
2425 test ( 'is assigned a <div> tag' , ( ) => {
25- render ( ( ) => (
26+ const { unmount } = render ( ( ) => (
2627 < HidingHeader > Header</ HidingHeader >
2728 ) ) ;
28- // screen.getByRole('button', { name: '' });
2929
30- const containerElm = screen . getByRole ( 'banner' , { name : '' } ) ;
30+ const containerElm = screen . getByRole ( 'banner' ) ;
3131 console . log ( containerElm . tagName ) ;
3232 expect ( containerElm . tagName ) . toBe ( 'DIV' ) ;
33+ unmount ( ) ;
3334 } ) ;
3435
3536 test ( 'is assigned a <header> tag' , ( ) => {
36- render ( ( ) => (
37+ const { unmount } = render ( ( ) => (
3738 < HidingHeader component = "header" > Header</ HidingHeader >
3839 ) ) ;
39- // screen.getByRole('button', { name: '' });
4040
41- const containerElm = screen . getByRole ( 'banner' , { name : '' } ) ;
41+ const containerElm = screen . getByRole ( 'banner' ) ;
4242 expect ( containerElm . tagName ) . toBe ( 'HEADER' ) ;
43+ unmount ( ) ;
4344 } ) ;
4445
4546 test ( 'Top Level element has correct default class assigned' , ( ) => {
46- render ( ( ) => (
47+ const { unmount } = render ( ( ) => (
4748 < HidingHeader >
4849 < div class = "inner" >
4950 < p > Header</ p >
5051 </ div >
5152 </ HidingHeader >
5253 ) ) ;
5354
54- const containerElm = screen . getByRole ( 'banner' , { name : '' } ) ;
55+ const containerElm = screen . getByRole ( 'banner' ) ;
5556 expect ( containerElm ) . toHaveClass ( 'hidingHeader' ) ;
57+ unmount ( ) ;
5658 } ) ;
5759
5860 test ( 'Top Level element has correct default style assigned' , ( ) => {
59- render ( ( ) => (
61+ const { unmount } = render ( ( ) => (
6062 < HidingHeader >
6163 < div class = "inner" >
6264 < p > Header</ p >
6365 </ div >
6466 </ HidingHeader >
6567 ) ) ;
6668
67- const containerElm = screen . getByRole ( 'banner' , { name : '' } ) ;
69+ const containerElm = screen . getByRole ( 'banner' ) ;
6870
6971 // Bug for `toHaveStyle()` on CSS Custom Property @ https://github.com/testing-library/jest-dom/issues/280
7072 // expect(containerElm).toHaveStyle(`--hidingHeader-height: 0px;`);
@@ -79,57 +81,64 @@ describe('HidingHeader component', () => {
7981 expect ( containerElm . style . _values ) . toMatchObject ( {
8082 '--hidingHeader-height' : '0px' ,
8183 } ) ;
84+ unmount ( ) ;
8285 } ) ;
8386
8487 test ( 'Top Level element has correct additional classes assigned' , ( ) => {
85- render ( ( ) => (
88+ const { unmount } = render ( ( ) => (
8689 < HidingHeader class = "bg-black" >
8790 < div class = "inner" >
8891 < p > Header</ p >
8992 </ div >
9093 </ HidingHeader >
9194 ) ) ;
9295
93- const containerElm = screen . getByRole ( 'banner' , { name : '' } ) ;
96+ const containerElm = screen . getByRole ( 'banner' ) ;
9497 expect ( containerElm ) . toHaveClass ( 'hidingHeader' , 'bg-black' ) ;
98+ unmount ( ) ;
9599 } ) ;
96100
97101 test ( 'inner element has correct default class assigned' , ( ) => {
98- render ( ( ) => (
102+ const { unmount } = render ( ( ) => (
99103 < HidingHeader >
100104 < div class = "inner" >
101105 < p > Header</ p >
102106 </ div >
103107 </ HidingHeader >
104108 ) ) ;
105109
106- const innerElm = screen . getByRole ( 'banner' , { name : '' } ) . querySelector ( 'div' ) ;
110+ const containerElm = screen . getByRole ( 'banner' ) ;
111+ const innerElm = containerElm . querySelector ( 'div' ) ;
107112 expect ( innerElm ) . toHaveClass ( 'hidingHeader-in' ) ;
113+ unmount ( ) ;
108114 } ) ;
109115
110116 test ( 'inner element has correct additional classes assigned' , ( ) => {
111- render ( ( ) => (
117+ const { unmount } = render ( ( ) => (
112118 < HidingHeader innerClass = "bg-black" >
113119 < div class = "inner" >
114120 < p > Header</ p >
115121 </ div >
116122 </ HidingHeader >
117123 ) ) ;
118124
119- const innerElm = screen . getByRole ( 'banner' , { name : '' } ) . querySelector ( 'div' ) ;
125+ const containerElm = screen . getByRole ( 'banner' ) ;
126+ const innerElm = containerElm . querySelector ( 'div' ) ;
120127 expect ( innerElm ) . toHaveClass ( 'hidingHeader-in' , 'bg-black' ) ;
128+ unmount ( ) ;
121129 } ) ;
122130
123131 test ( 'should have a element' , ( ) => {
124- render ( ( ) => (
132+ const { unmount } = render ( ( ) => (
125133 < HidingHeader >
126134 < div class = "inner" >
127135 < p > Header</ p >
128136 </ div >
129137 </ HidingHeader >
130138 ) ) ;
131139
132- const headerElm = screen . getByText ( / ^ H e a d e r $ / i ) ; // full string match, ignore case
140+ const headerElm = screen . getByText ( ' Header' ) ; // Use exact text match instead of regex
133141 expect ( headerElm ) . toBeInTheDocument ( ) ;
142+ unmount ( ) ;
134143 } ) ;
135144} ) ;
0 commit comments