Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting ReferenceError: ResizeObserver is not defined, while not using it

I'm new to react testing, getting this (ReferenceError: ResizeObserver is not defined) error but i'm not using it anywhere, i think problem is with allotment library example : https://codesandbox.io/s/6bdt88

any idea with this error ?

enter image description here

import React from "react";
import Page from "../Page";
import { Provider } from "react-redux";
import { store } from "../../redux/store";

import "@testing-library/jest-dom/extend-expect";


describe("Testing component Page", () => {
  const Navbar = (): RenderResult =>
    render(
      <Provider store={store}>
        <MemoryRouter>
          <Page />
        </MemoryRouter>
      </Provider>
    );

  test("Testing Page", () => {
    Navbar();
    
  });
});
like image 796
waleedd32 Avatar asked Jun 26 '26 12:06

waleedd32


1 Answers

Apprently Allotment library uses 'ResizeObserver' and in your setupTests.js(if you dont have it, just create it) file paste this and it will fix it:

global.ResizeObserver = jest.fn().mockImplementation(() => ({
    observe: jest.fn(),
    unobserve: jest.fn(),
    disconnect: jest.fn(),
}))
like image 180
waleedd32 Avatar answered Jun 29 '26 01:06

waleedd32



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!