Usage with jest
See original GitHub issueHi!
I wanted to test a shallow mounted component with jest and vue-test-utils@next and as you could imagine I run into
No queryClient found in Vue context, use 'useQueryProvider' to set one in the root component.
Any ideas how to approch this issue besides writing a jest mock?
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Jest · Delightful JavaScript Testing
Jest is a JavaScript testing framework designed to ensure correctness of any JavaScript codebase. It allows you to write tests with an approachable,...
Read more >Jest Tutorial for Beginners: Getting Started With JavaScript ...
Jest is a JavaScript test runner, that is, a JavaScript library for creating, running, and structuring tests. Jest ships as an NPM package,...
Read more >What Is Jest – A Tutorial on How to Use Jest - LambdaTest
Usage : According to the State of JS survey, Jest has been the most widely used testing framework for JavaScript testing, among other...
Read more >Jest Tutorial - JavaScript Unit Testing Using Jest Framework
In this Jest tutorial, we will learn about various Jest features, Jest matchers and how to use Jest framework for JavaScript Unit Testing....
Read more >Jest Testing Tutorial: 5 Easy Steps - Testim Blog
Jest itself is actually not a library but a framework. There's even a CLI tool that you can use from the command line....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, If you do not want to incorporate jest mock, you can write a tiny plugin wrapper in your project. Then when the library will expose its own plugin, you can just change the import without additional changes.
Something like this should work for you:
and then call it in your test file
@sem4phor I took a look at the reproduction repository and noticed few issues:
node-fetch
for jest environmentTo fix it you could:
fetch
to fix all the issues.node-fetch
as dev dependency and assign it viaimport fetch from "node-fetch"; global.fetch = fetch;
insetup.js
. This will solve the issue with jest throwing an error thatfetch
is not defined. But do not solve third issue.flushPromises
that would wait for ex. 100ms before next assertion.Also you should disable retries on failure (this will make the second issue from above clearly visible) in vue-query by providing config to
QueryClient
. Ex from your repo:If you fix those issues, tests would work as intended.