Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Flow aware of Jest's globals (test, expect, etc)?

I get these Flow errors in my test files:

identifier `test`
Could not resolve name

identifier `expect`
Could not resolve name

I've installed the Jest libdef from flow-typed but it doesn't make any difference.


Update: it looks like the Jest libdef created by flow-typed is just a stub. I think the problem is that flow-typed doesn't have a libdef for Jest v0.21.x yet.

like image 661
callum Avatar asked Sep 14 '17 11:09

callum


People also ask

How do you run a Jest test?

In order to run a specific test, you'll need to use the jest command. npm test will not work. To access jest directly on the command line, install it via npm i -g jest-cli or yarn global add jest-cli . Then simply run your specific test with jest bar.

What is Je beforeEach?

beforeEach(fn) #Runs a function before each of the tests in this file runs. If the function returns a promise, Jest waits for that promise to resolve before running the test. This is often useful if you want to reset some global state that will be used by many tests.

What is describe and test in Jest?

describe breaks your test suite into components. Depending on your test strategy, you might have a describe for each function in your class, each module of your plugin, or each user-facing piece of functionality. You can also nest describes to further subdivide the suite. it is where you perform individual tests.


1 Answers

What's the right way to write Jest tests verified with Flow?

flow-typed now has all versions of Jest: https://github.com/flowtype/flow-typed/tree/master/definitions/npm

like image 169
sharno Avatar answered Sep 19 '22 14:09

sharno