You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just used patch-package to patch react-intersection-observer@9.14.0 for the project I'm working on. I don't think this is the best fix, but it resolved an issue I'd been having.
In some of our existing test files we have to do a little trick like this:
// https://github.com/testing-library/react-testing-library/issues/1197#issuecomment-1693824628// @ts-expect-error type hoohaaglobalThis.jest={advanceTimersByTime: vi.advanceTimersByTime.bind(vi)};
You can check out the RTL issue link for more context of why we have to do this. There may be a better way, but this has worked for our project for almost a year without any issues.
I added react-intersection-observer to our project today and used react-intersection-observer/test-utils. We then started getting TypeScript errors like these:
src/app/(shopfront)/(simplified)/checkout/payment/complete/CompletePage.test.tsx:71:5 - error TS2353: Object literal may only specify known properties, and 'advanceTimersByTime' does not exist in type '{ fn: <T extends Procedure = Procedure>(implementation?: T | undefined) => Mock<T>; }'.
71 advanceTimersByTime: vi.advanceTimersByTime.bind(vi)
~~~~~~~~~~~~~~~~~~~
The global jest type from react-intersection-observer/test-utils was affecting our test files and resulting in errors.
I was wondering if the type from react-intersection-observer/test-utils needs to be global? If that type is just for your own development needs then a module-scope type might be better, I think?
Here is the diff that solved my problem:
diff --git a/node_modules/react-intersection-observer/test-utils/index.d.mts b/node_modules/react-intersection-observer/test-utils/index.d.mts
index 58a5d85..464972a 100644
--- a/node_modules/react-intersection-observer/test-utils/index.d.mts+++ b/node_modules/react-intersection-observer/test-utils/index.d.mts@@ -1,9 +1,3 @@-declare global {- var IS_REACT_ACT_ENVIRONMENT: boolean;- var jest: {- fn: typeof vi.fn;- } | undefined;-}
/**
* Create a custom IntersectionObserver mock, allowing us to intercept the `observe` and `unobserve` calls.
* We keep track of the elements being observed, so when `mockAllIsIntersecting` is triggered it will
diff --git a/node_modules/react-intersection-observer/test-utils/index.d.ts b/node_modules/react-intersection-observer/test-utils/index.d.ts
index 58a5d85..464972a 100644
--- a/node_modules/react-intersection-observer/test-utils/index.d.ts+++ b/node_modules/react-intersection-observer/test-utils/index.d.ts@@ -1,9 +1,3 @@-declare global {- var IS_REACT_ACT_ENVIRONMENT: boolean;- var jest: {- fn: typeof vi.fn;- } | undefined;-}
/**
* Create a custom IntersectionObserver mock, allowing us to intercept the `observe` and `unobserve` calls.
* We keep track of the elements being observed, so when `mockAllIsIntersecting` is triggered it will
This makes sense - I guess we might just have ignore types jest, so we don't get it mixed up. The variables are set globally by Jest/Testing Library. Not sure if there's another way of defining global variables scoped to a module?
Hi, thanks for your work on this package :)
I just used patch-package to patch
react-intersection-observer@9.14.0
for the project I'm working on. I don't think this is the best fix, but it resolved an issue I'd been having.In some of our existing test files we have to do a little trick like this:
You can check out the RTL issue link for more context of why we have to do this. There may be a better way, but this has worked for our project for almost a year without any issues.
I added
react-intersection-observer
to our project today and usedreact-intersection-observer/test-utils
. We then started getting TypeScript errors like these:The global
jest
type fromreact-intersection-observer/test-utils
was affecting our test files and resulting in errors.I was wondering if the type from
react-intersection-observer/test-utils
needs to be global? If that type is just for your own development needs then a module-scope type might be better, I think?Here is the diff that solved my problem:
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: