How to mock a library function in jest
I tried doing .spyOn to spy on the function but it didn't work. I don't think .mock works because it requires a module script, and roblox-ts strings will mess up its mockings
13 Replies
in my use case, I tried mocking matter's useDeltaTime function to return a deseried delta time value, but I can't find out how to do that
You need to dynamically import
I did something like:
and then my code looked like:
you need to ensure you mock it before you import it
what is getServices?
just mock the module that exports getdeltatime no?
make sure the mock is setup before importing anything else that might import matter aswell
it was just
I tried doing something like this. But it didn't work
do I have to wrap this in another module and export the mocked version of useDeltaTime
it should work if u do this part correctly
whats your code exactly?
move these imports below the usedt mock

except jest globals
eslint will get mad at me 😅
Might need to turn it off for spec files or do something else, the import order matters here, which is why I did the dynamic import
ngl this feels very hacky
I might not do it