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

Flow type support? #607

Closed
aksonov opened this issue Nov 11, 2015 · 18 comments
Closed

Flow type support? #607

aksonov opened this issue Nov 11, 2015 · 18 comments
Assignees

Comments

@aksonov
Copy link

aksonov commented Nov 11, 2015

I'm trying to use flow syntax within unit tests, but i don't see any way to test it

 - Error: Line 5: Unexpected token :
        at createError (node_modules/jest-cli/node_modules/istanbul/node_modules/esprima/esprima.js:2392:21)
        at unexpectedTokenError (node_modules/jest-cli/node_modules/istanbul/node_modules/esprima/esprima.js:2467:13)
        at throwUnexpectedToken (node_modules/jest-cli/node_modules/istanbul/node_modules/esprima/esprima.js:2472:15)
        at parseClassBody (node_modules/jest-cli/node_modules/istanbul/node_modules/esprima/esprima.js:5045:21)
        at parseClassDeclaration (node_modules/jest-cli/node_modules/istanbul/node_modules/esprima/esprima.js:5067:21)
        at parseStatementListItem (node_modules/jest-cli/node_modules/istanbul/node_modules/esprima/esprima.js:3935:24)
        at parseFunctionSourceElements (node_modules/jest-cli/node_modules/istanbul/node_modules/esprima/esprima.js:4766:23)
        at parseFunctionExpression (node_modules/jest-cli/node_modules/istanbul/node_modules/esprima/esprima.js:4972:16)
        at parsePrimaryExpression (node_modules/jest-cli/node_modules/istanbul/node_modules/esprima/esprima.js:3232:24)
        at inheritCoverGrammar (node_modules/jest-cli/node_modules/istanbul/node_modules/esprima/esprima.js:2648:18)
@cpojer
Copy link
Member

cpojer commented Nov 11, 2015

I suggest using babel-jest to preprocess your files and strip flow-annotations before tests are being run on them. Follow the guide for React testing on the bottom here: http://facebook.github.io/jest/docs/tutorial-react.html#content

(Note: we are in the process of upgrading babel-jest to babel6. For now I recommend using babel-jest 5 until we have ironed out the issues).

@cpojer cpojer closed this as completed Nov 11, 2015
@aksonov
Copy link
Author

aksonov commented Nov 11, 2015

Thanks, problem was exactly with usage of babel 6 ! Babel-jest 5 works like a charm.

@kevinastone
Copy link

@cpojer, that tutorial didn't explain how to install the babel plugin transform-flow-strip-types. Could we add a note?

@cpojer
Copy link
Member

cpojer commented Nov 21, 2016

I think we should add some notes for this somewhere. cc @hramos.

@hramos hramos self-assigned this Nov 28, 2016
@thomb
Copy link

thomb commented Apr 6, 2017

FWIW Here is the transformer I put together to get jest running with transform-flow-strip-types after npm install --save-dev babel-plugin-transform-flow-strip-types

const babelJest = require('babel-jest');
const jestPreset = require('babel-preset-jest');

module.exports = babelJest.createTransformer({
	plugins: [
		"transform-flow-strip-types"
	],
	presets: [jestPreset]
});

@hramos
Copy link
Contributor

hramos commented Apr 6, 2017

Ooof, I wasn't aware this was an issue people might need help with. If you still think this should be documented, feel free to open a new issue and assign it to me.

@thomb
Copy link

thomb commented Apr 6, 2017

The only reason I commented here (which I now realize was closed, my bad) is the last comment saying "yeah, we should document this!"

@hramos
Copy link
Contributor

hramos commented Apr 6, 2017

Yeah! That is on me to document. Unfortunately it's not been on my mind as the issue is closed.

@thymikee
Copy link
Collaborator

thymikee commented Apr 7, 2017

@thomb transform-flow-strip-types plugin (or flow preset) just works with Jest when added to your Babel config.

@jsdario
Copy link

jsdario commented Apr 26, 2017

Hi @thymikee, do you have a sample? I imagine that requires several configurations for prod, dev and testing.

@thymikee
Copy link
Collaborator

.babelrc

{
  "presets": [
    "flow"
  ]
}

That's all.

@rayrutjes
Copy link

Is it exepected that this doesn't work with jest?

export default class {
  urlsToVisit: { [string]: boolean } = {};
}

Error being Unexpected token:

image

@cpojer
Copy link
Member

cpojer commented Sep 3, 2017

Flow is supported, if you are getting this error, it's because you didn't properly set up your babel build pipeline.

@rayrutjes
Copy link

@cpojer Well I'm using the flow preset, and I think it's an error specific to jest, given it works fine when I just use yarn run flow.

@archiewx
Copy link

@aksonov
Finally, can you tell me how to solve this problem?

@yiakwy
Copy link

yiakwy commented Jun 27, 2018

I am adding a jest feature to unity tests, @thomb, compilation broken. It does not work for me. am I missing anything?

@kaladivo
Copy link

I have the same problem as @rayrutjes. Is there any solution to it?

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests