11import "@testing-library/jest-dom" ;
2- import { render } from "@testing-library/react" ;
32
4- import { ImageColorSchemeSwitch , getLogoSrc } from "./ImageColorSchemeSwitch" ;
5-
6- jest . mock ( "@mui/material" , ( ) => {
7- return {
8- useColorScheme : jest . fn ( ) . mockReturnValue ( { mode : "dark" } ) ,
9- } ;
10- } ) ;
3+ import { ImageColorSchemeSwitch } from "./ImageColorSchemeSwitch" ;
4+ import { renderWithProviders } from "../__test-utils__/helpers" ;
5+ import { screen } from "@testing-library/react" ;
116
127describe ( "ImageColorSchemeSwitch" , ( ) => {
138 const testVals = {
@@ -22,17 +17,17 @@ describe("ImageColorSchemeSwitch", () => {
2217 width ?: string ;
2318 height ?: string ;
2419 } ) {
25- const { getByAltText } = render (
20+ const { getByTestId } = renderWithProviders (
2621 < ImageColorSchemeSwitch image = { { ...testVals , ...image } } /> ,
2722 ) ;
2823
29- const img = getByAltText ( testVals . alt ) ;
24+ const img = getByTestId ( "image-light" ) ;
3025 expect ( img ) . toBeInTheDocument ( ) ;
3126 return img ;
3227 }
3328
3429 it ( "should render without errors" , ( ) => {
35- render ( < ImageColorSchemeSwitch image = { { ...testVals } } /> ) ;
30+ renderWithProviders ( < ImageColorSchemeSwitch image = { { ...testVals } } /> ) ;
3631 } ) ;
3732
3833 it ( "should have src and alt by default" , ( ) => {
@@ -66,46 +61,12 @@ describe("ImageColorSchemeSwitch", () => {
6661 it ( "should have alternate src" , ( ) => {
6762 const srcDark = "src/dark" ;
6863
69- const img = getRenderImg ( {
70- srcDark,
71- } ) ;
72-
73- expect ( img ) . toHaveAttribute ( "src" , srcDark ) ;
74- } ) ;
75- } ) ;
76-
77- describe ( "getLogoSrc" , ( ) => {
78- const srcLight = "src/light" ,
79- srcDark = "src/dark" ;
80-
81- it ( "should be null if no image" , ( ) => {
82- // @ts -expect-error: invalid input
83- expect ( getLogoSrc ( null , "" ) ) . toStrictEqual ( undefined ) ;
84- // @ts -expect-error: invalid input, calm down ts
85- expect ( getLogoSrc ( ) ) . toStrictEqual ( undefined ) ;
86- } ) ;
87-
88- it ( "should be srcLight if no srcDark" , ( ) => {
89- expect ( getLogoSrc ( { src : srcLight , alt : "" } , "light" ) ) . toStrictEqual (
90- srcLight ,
64+ renderWithProviders (
65+ < ImageColorSchemeSwitch image = { { ...testVals , srcDark } } /> ,
66+ { defaultMode : "dark" } ,
9167 ) ;
92- } ) ;
68+ const img = screen . getByTestId ( "image-dark" ) ;
9369
94- it ( "should be srcLight if mode is dark but no srcDark" , ( ) => {
95- expect ( getLogoSrc ( { src : srcLight , alt : "" } , "dark" ) ) . toStrictEqual (
96- srcLight ,
97- ) ;
98- } ) ;
99-
100- it ( "should be srcLight if srcDark but mode light" , ( ) => {
101- expect (
102- getLogoSrc ( { src : srcLight , srcDark : srcDark , alt : "" } , "light" ) ,
103- ) . toStrictEqual ( srcLight ) ;
104- } ) ;
105-
106- it ( "should be srcDark if mode dark" , ( ) => {
107- expect (
108- getLogoSrc ( { src : "src/light" , srcDark : srcDark , alt : "" } , "dark" ) ,
109- ) . toStrictEqual ( srcDark ) ;
70+ expect ( img ) . toHaveAttribute ( "src" , srcDark ) ;
11071 } ) ;
11172} ) ;
0 commit comments