How to use jest flow-types in tests
See original GitHub issueAfter running flow-typed install
and getting package flow-typed/npm/jest_v21.x.x.js
, how are we supposed to use these types? The names that flow check
requires are not resolving
For example, this fails with the following messages:
Missing type annotation for TArguments
AND Cannot resolve name TArguments
export const fn = jest.fn(...args: TArguments): TReturn => {
...
};
Here’s an untyped boilerplate example of what I am having issues with:
// @flow
// fetch mock
export const fn = jest.fn(() => (url, params) => {
console.log(params);
console.log(url);
return new Promise(resolve => resolve({ ok: true, status: 200 }));
});
export default jest.mock('../../src/shared/fetch', fn);
And here are the errors flow is giving me:
Error ------------------------------------------------------------------------------------------------- untitled.js:3:19
Missing type annotation for `TArguments`.
v-------------------------------
3| export const fn = jest.fn(() => (url, params) => {
4| console.log(params);
5| console.log(url);
6| return new Promise(resolve => resolve({ ok: true, status: 200 }));
7| });
-^
Error ------------------------------------------------------------------------------------------------- untitled.js:3:19
Missing type annotation for `TReturn`.
v-------------------------------
3| export const fn = jest.fn(() => (url, params) => {
4| console.log(params);
5| console.log(url);
6| return new Promise(resolve => resolve({ ok: true, status: 200 }));
7| });
-^
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Running Jest tests with Flow typed Javascript files
This will be a simple tutorial about running Jest tests with Flow typed Javascript files in NodeJS project.
Read more >What's the right way to write Jest tests verified with Flow?
1.Install flow to your project. If you use create-reat-app, here is a guide for this step. yarn add -D flow-bin yarn run flow...
Read more >Jest 13.0: Flow & REPL
The Flow types serve two purposes: First, we believe that code is written to be read. Most of the time, code is written...
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 Tutorial for Beginners: Getting Started With JavaScript ...
In this Jest tutorial we'll cover only unit testing, but at the end of the article you'll find resources for the other types...
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 FreeTop 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
Top GitHub Comments
@sobolevn solution doesn’t work for me
I’m getting babel parser errors: “Unexpected token”
My babel config:
@cortopy I had the same parsing error as you when using the provided example, but was able to move the type annotations to the left-hand-side of the assignment to get a version that worked 🙂