In specific testing Environments, it is possible for setTimeout to not clear after each test. Causing my test to fail with a window not defined error
Error I'm recieving:
ReferenceError: window is not defined
❯ Timeout.e [as onTimeout] node_modules/.pnpm/@react-input+core@1.0.12@types+react@18.2.79_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@react-input/core/dist/module/hooks/useInput.js:1:1751
I believe the fix is to always clearTimeout when component is unmounted / unregistered.
Currently, I believe timeouts are only cleared onBlur of the input.
|
window.clearTimeout(timeout.id); |
Workaround
For those Running into a similar error, I was able to avoid this issue by invoking the blur() function after each test so the timeouts are cleared.
afterEach(() => {
const activeElement = global.document?.activeElement
if (activeElement && activeElement instanceof HTMLElement) {
activeElement.blur()
}
})
In specific testing Environments, it is possible for
setTimeoutto not clear after each test. Causing my test to fail with a window not defined errorError I'm recieving:
I believe the fix is to always
clearTimeoutwhen component is unmounted / unregistered.Currently, I believe timeouts are only cleared
onBlurof the input.react-input/packages/core/src/Input.ts
Line 106 in 7ca98d5
Workaround
For those Running into a similar error, I was able to avoid this issue by invoking the
blur()function after each test so the timeouts are cleared.