@@ -2,8 +2,7 @@ import React from 'react'
22import { render } from '@testing-library/react'
33import { Hidden } from '.'
44import MatchMediaMock from 'jest-matchmedia-mock'
5- import { behavesAsComponent , checkExports , renderStyles , checkStoriesForAxeViolations } from '../utils/testing'
6- import { mediaQueries } from '../utils/layout'
5+ import { behavesAsComponent , checkExports , checkStoriesForAxeViolations } from '../utils/testing'
76
87let matchMedia : MatchMediaMock
98describe ( 'Hidden' , ( ) => {
@@ -40,37 +39,31 @@ describe('Hidden', () => {
4039 } )
4140
4241 it ( 'renders the styles as expected when a single viewport value is provided as a string via `when` prop' , ( ) => {
43- const expectedStyles = {
44- // `.replace` is used because renderStyles return the JSON object without a space after the column
45- [ `${ mediaQueries . regular . replace ( ': ' , ':' ) } ` ] : {
46- display : 'none' ,
47- } ,
48- }
49- expect (
50- renderStyles (
42+ const hiddenElement = render (
43+ < div data-testid = "hidden-regular" >
5144 < Hidden when = "regular" >
5245 < div > This is hidden when regular viewports</ div >
53- </ Hidden > ,
54- ) ,
55- ) . toEqual ( expect . objectContaining ( expectedStyles ) )
46+ </ Hidden >
47+ </ div > ,
48+ )
49+ expect ( hiddenElement . getAllByTestId ( 'hidden-regular' ) [ 0 ] . firstChild ) . toHaveAttribute (
50+ 'style' ,
51+ '--hiddenDisplay-regular: none;' ,
52+ )
5653 } )
5754
5855 it ( 'renders the styles as expected when multiple viewport values are provided as an array via `when` prop' , ( ) => {
59- const expectedStyles = {
60- [ `${ mediaQueries . narrow . replace ( ': ' , ':' ) } ` ] : {
61- display : 'none' ,
62- } ,
63- [ `${ mediaQueries . wide . replace ( ': ' , ':' ) } ` ] : {
64- display : 'none' ,
65- } ,
66- }
67- expect (
68- renderStyles (
56+ const hiddenElement = render (
57+ < div data-testid = "hidden-regular" >
6958 < Hidden when = { [ 'narrow' , 'wide' ] } >
70- < div > This is hidden when regular and wide viewports</ div >
71- </ Hidden > ,
72- ) ,
73- ) . toEqual ( expect . objectContaining ( expectedStyles ) )
59+ < div > This is hidden when regular viewports</ div >
60+ </ Hidden >
61+ </ div > ,
62+ )
63+ expect ( hiddenElement . getAllByTestId ( 'hidden-regular' ) [ 0 ] . firstChild ) . toHaveAttribute (
64+ 'style' ,
65+ '--hiddenDisplay-narrow: none; --hiddenDisplay-wide: none;' ,
66+ )
7467 } )
7568} )
7669
0 commit comments