1+ /* global window */
12import * as React from 'react' ;
23import userEvent from '@testing-library/user-event' ;
34
@@ -7,6 +8,21 @@ import { render as defaultRender, screen } from 'tests/unit/helpers';
78const HEIGHT = 400 ;
89const WIDTH = 200 ;
910
11+ // See: https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
12+ Object . defineProperty ( window , 'matchMedia' , {
13+ writable : true ,
14+ value : jest . fn ( ) . mockImplementation ( ( query ) => ( {
15+ matches : false ,
16+ media : query ,
17+ onchange : null ,
18+ addListener : jest . fn ( ) , // deprecated
19+ removeListener : jest . fn ( ) , // deprecated
20+ addEventListener : jest . fn ( ) ,
21+ removeEventListener : jest . fn ( ) ,
22+ dispatchEvent : jest . fn ( ) ,
23+ } ) ) ,
24+ } ) ;
25+
1026describe ( __filename , ( ) => {
1127 const testPreviews = [
1228 {
@@ -53,34 +69,7 @@ describe(__filename, () => {
5369
5470 await userEvent . click ( screen . getByAltText ( testPreviews [ 0 ] . title ) ) ;
5571
56- // Verifying the output of PHOTO_SWIPE_OPTIONS.
57- // closeEl: true,
58- expect ( screen . getByTitle ( 'Close (Esc)' ) ) . not . toHaveClass (
59- 'pswp__element--disabled' ,
60- ) ;
61- // captionEl: true,
62- expect ( screen . getAllByText ( testPreviews [ 0 ] . title ) ) . toHaveLength ( 2 ) ;
63- // fullscreenEl: false,
64- expect ( screen . getByTitle ( 'Toggle fullscreen' ) ) . toHaveClass (
65- 'pswp__element--disabled' ,
66- ) ;
67- // zoomEl: false,
68- expect ( screen . getByTitle ( 'Zoom in/out' ) ) . toHaveClass (
69- 'pswp__element--disabled' ,
70- ) ;
71- // shareEl: false,
72- expect ( screen . getByTitle ( 'Share' ) ) . toHaveClass ( 'pswp__element--disabled' ) ;
73- // counterEl: true,
74- expect ( screen . getByText ( '1 / 2' ) ) . toBeInTheDocument ( ) ;
75- // arrowEl: true,
76- expect ( screen . getByTitle ( 'Previous (arrow left)' ) ) . not . toHaveClass (
77- 'pswp__element--disabled' ,
78- ) ;
79- expect ( screen . getByTitle ( 'Next (arrow right)' ) ) . not . toHaveClass (
80- 'pswp__element--disabled' ,
81- ) ;
82- // preloaderEl: true,
83- expect ( screen . getByClassName ( 'pswp__preloader' ) ) . toBeInTheDocument ( ) ;
72+ expect ( screen . getByText ( testPreviews [ 0 ] . title ) ) . toBeInTheDocument ( ) ;
8473 } ) ;
8574
8675 // eslint-disable-next-line jest/no-commented-out-tests
@@ -98,11 +87,11 @@ describe(__filename, () => {
9887
9988 it('scrolls to the active item on close', async () => {
10089 const { unmount } = render();
101-
90+
10291 // eslint-disable-next-line testing-library/no-node-access
10392 const list = document.querySelector('.ScreenShots-list');
10493 const scrollLeft = jest.spyOn(list, 'scrollLeft', 'set');
105-
94+
10695 // This clicks the Escape key.
10796 fireEvent.keyDown(screen.getByAltText(testPreviews[0].title), {
10897 key: 'Escape',
@@ -113,7 +102,7 @@ describe(__filename, () => {
113102 await userEvent.keyboard('[Escape]');
114103 await userEvent.keyboard('{esc}');
115104 unmount();
116-
105+
117106 await waitFor(() => expect(scrollLeft).toHaveBeenCalled());
118107 });
119108 */
0 commit comments