1- /// <reference types="@testing-library/jest-dom" />
21import { render , screen } from '@testing-library/react' ;
3- import React from 'react' ;
42import { describe , expect , it , vi } from 'vitest' ;
53
64import Switch from './Switch' ;
@@ -64,9 +62,7 @@ describe('Switch - Variants', () => {
6462 render ( < Switch checked = { false } variant = "default" /> ) ;
6563
6664 const switchElement = screen . getByRole ( 'switch' ) ;
67- // Check for arbitrary variant classes that style the thumb
68- expect ( switchElement . className ) . toMatch ( / \[ & > s p a n \] : h - 4 / ) ;
69- expect ( switchElement . className ) . toMatch ( / \[ & > s p a n \] : w - 4 / ) ;
65+ expect ( switchElement ) . toHaveClass ( '[&>span]:size-4' ) ;
7066 } ) ;
7167
7268 it ( 'should render small variant with correct track dimensions' , ( ) => {
@@ -84,9 +80,7 @@ describe('Switch - Variants', () => {
8480 render ( < Switch checked = { false } variant = "small" /> ) ;
8581
8682 const switchElement = screen . getByRole ( 'switch' ) ;
87- // Check for arbitrary variant classes for small thumb
88- expect ( switchElement . className ) . toMatch ( / \[ & > s p a n \] : h - 3 / ) ;
89- expect ( switchElement . className ) . toMatch ( / \[ & > s p a n \] : w - 3 / ) ;
83+ expect ( switchElement ) . toHaveClass ( '[&>span]:size-3' ) ;
9084 } ) ;
9185
9286 it ( 'should render box variant with correct track dimensions' , ( ) => {
@@ -260,7 +254,6 @@ describe('Switch - Focus', () => {
260254 render ( < Switch checked = { false } /> ) ;
261255
262256 const switchElement = screen . getByRole ( 'switch' ) ;
263- expect ( switchElement ) . toHaveClass ( 'focus-visible:outline-none' ) ;
264257 expect ( switchElement ) . toHaveClass ( 'focus-visible:ring-2' ) ;
265258 expect ( switchElement ) . toHaveClass ( 'focus-visible:ring-stroke-brand-focus' ) ;
266259 expect ( switchElement ) . toHaveClass ( 'focus-visible:ring-offset-0' ) ;
0 commit comments