0

I had make a slider with GlideJS. This widget is working fine. But when I am writing the jest test. My Test is failing, it's saying TypeError: Cannot read property 'querySelector' of undefined. Here is the complete error while I am playing the test case.

    TypeError: Cannot read property 'querySelector' of undefined

  55 |     const slider = new Glide(sliderRef.current, options);
  56 |
> 57 |     slider.mount();
     |            ^
  58 |   }, [options]);
  59 |
  60 |   const handleOnMouseEnter = () => setNavigationVisible(true);

Here is the Test Suite which I write down.

import React from 'react';
import renderer from 'react-test-renderer';
import Widget from './Widget';

const mockArray = [
  { title: 'Mock Title 1', completed: false },
  { title: 'Mock Title 2', completed: false },
  { title: 'Mock Title 3', completed: false },
];
describe('Widget', () => {
  it('renders Widget according to design', () => {
    const component = renderer.create(
      <Widget lessons={mockArray} title={'mock title'} />
    );
    const tree = component.toJSON();

    expect(tree).toMatchSnapshot();
  });
});
Arslan Ali
  • 408
  • 1
  • 6
  • 16

0 Answers0