recharts / react-smooth

react animation
MIT License
277 stars 38 forks source link

Check if requestAnimationFrame is defined in shouldUpdate #81

Closed branberry closed 11 months ago

branberry commented 11 months ago

Fixes test issues with Vitest in Recharts

branberry commented 11 months ago

Hey @ckifer ! Do you mean something like !!requestAnimationFrame? I haven't tried that, but when I was debugging this code in the Vitest tests, doing the following still gave me the requestAnimationFrame is undefined error:

 if (!requestAnimationFrame) { ... }

Typically wouldn't do the whole typeof stuff, but for whatever reason, this was the only way to ensure that it wouldn't error out when checking.

ckifer commented 11 months ago

Weird yeah the second way is what I was thinking should work? Strange... generally I would think libraries shouldn't have to adjust for a test framework but.. makes sense I guess?

branberry commented 11 months ago

Yeah.. It was really bizarre. I think it's all related to VItest interacting with the react-testing-library which leads to fake timers not working: https://github.com/testing-library/react-testing-library/issues/1198

When making the tests async, stuff just didn't want to behave nicely for the animated tests, and the library would still be calling requestAnimationFrame after the tests have completed, so I think this is why we ran into this. I also debugged into some gnarly Vitest code, and it looked like that was the case.

ckifer commented 11 months ago

JsDom in general is probably a lot of the issue because everything animation and actual dom testing wise needs to be mocked