razorpay / blade

Design System that powers Razorpay
https://blade.razorpay.com
MIT License
495 stars 129 forks source link

"ResizeObserver is not defined" error when running Jest #1367

Closed joel-jaimon closed 1 year ago

joel-jaimon commented 1 year ago

Getting this error when running Jest with v8.11.3.

Screenshot 2023-06-27 at 1 12 17 PM
kkyusufk commented 1 year ago

@joel-jaimon can you add more context around the issue? Maybe a steps to reproduce.

chaitanyadeorukhkar commented 1 year ago

You can mock it with this:

global.ResizeObserver = jest.fn().mockImplementation(() => ({
  observe: jest.fn(),
  unobserve: jest.fn(),
  disconnect: jest.fn(),
}));
joel-jaimon commented 1 year ago

I had to mock it in the end, but I just wanted to check with you folks if this can be resolved from the lib itself.

chaitanyadeorukhkar commented 1 year ago

Not sure if we'll be able to resolve it on lib end since it would always be client's jest that doesn't have any definitions for ResizeObserver. I can add this to the FAQ section though

prabhasjoshi commented 1 year ago

I was also facing the same error - so i setup the mocking for it in my projects initJest.js file

chaitanyadeorukhkar commented 1 year ago

Added in FAQ #1412. Closing this