How to provide a mocked value for a context in unit testing? #4658
Replies: 1 comment
-
If you're using the decorators, there are no functions to mock/spy. You're simply setting a provider property and the corresponding consumer property of a descendant component should take on that value. If you're writing an assertion for that consumed value, you'll need to wait for the update lifecycle to complete: https://lit.dev/docs/components/lifecycle/#reactive-update-cycle-completing Assuming you have references to elements in the DOM called
The only method I can see in the contexts API is if you were to create a Additionally, you can provide a callback function to an instance of But it seems like a great inconvenience to build your components with manual context controllers simply to have access to these affordances for testing purposes. I hope I understood your question correctly! |
Beta Was this translation helpful? Give feedback.
-
Basically I am wondering how to mock @provide @consume properties in a component when unit testing (in my case with jest).
I cannot really decipher from the docs how one could mock/spy on provided service via the context API.
Any help would be greatly appreciate it.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions