Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can we get useLiveQuery mocked for unit testing? #2070

Open
itmarck opened this issue Sep 16, 2024 · 1 comment
Open

How can we get useLiveQuery mocked for unit testing? #2070

itmarck opened this issue Sep 16, 2024 · 1 comment

Comments

@itmarck
Copy link

itmarck commented Sep 16, 2024

I'm making some unit tests for React components and the hook is not returning anything.

My question is what's the recommended way to implement a mock for a test environment or how can we set a default/initial value? I saw this hook implementation is coupled to the IndexedDb instance, but I guess there should be an alternative to be able to include the useLiveQuery hook on the tests.

@dfahlander
Copy link
Collaborator

That's right, If indexedDB isn't present (as it normally is not in node unless polyfilled with fakeIndexedDB or indexedDBShim), it won't ever try to execute the given querier callback. Instead the hook will return the defaultValue (3rd argument to useLiveQuery())

https://dexie.org/docs/dexie-react-hooks/useLiveQuery()#syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants