Jest-styled-components: Unexpected token ... after upgrading to 6.2.1

Created on 25 Sep 2018  Â·  9Comments  Â·  Source: styled-components/jest-styled-components

Hi,

After upgrading to 6.2.1 all my tests breaks:

.../node_modules/jest-styled-components/src/toHaveStyleRule.js:104
    const normalizeOptions = ({ modifier, ...options }) =>
                                          ^^^
    SyntaxError: Unexpected token ...
t ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at Object.<anonymous> (node_modules/jest-styled-components/src/index.js:1:114)
      at Object.<anonymous> (src/setupTests.js:11:51)

And my setupTests.js:

import 'jest-enzyme';
import 'jest-styled-components';

import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });

My package versions are:

"styled-components": "3.2.3",
"jest-enzyme": "6.1.2",
"react": "16.5.2",

Anyone has the same problem?

Thanks

Most helpful comment

Me too @MicheleBertoli

All 9 comments

just introduced jest-styled-components into a project, and got hit with this...

I'm facing the same issue when adding it to a project. From which version are you updating @albert-olive? Tried also 6.0.0 with no luck. 5.0.1 works great.

My versions are
"react": "16.5.0", "jest": "21.2.1", "styled-components": "3.4.9"

Hi @aserrabl, in my previous comment, you have my versions. Didn't updated yet because I'm having already this problem

I have the same issue, for what it's worth i've recently updated my project to create react app v2, could it be that?

"styled-components": "^3.4.9",
"polished": "^2.1.1",
"react": "^16.5.2",

Thanks for opening this issue, @albert-olive, and thanks for your comments, @mofax @aserrabl @SarantopoulosKon.

I assume you are using a version of node < 8.6, right?
Source: https://node.green/#ES2018-features-object-rest-spread-properties

The issue disappeared after I moved up to node v9.9.0

On Sat, 13 Oct 2018, 9:16 p.m. Michele Bertoli, notifications@github.com
wrote:

Thanks for opening this issue, @albert-olive
https://github.com/albert-olive, and thanks for your comments, @mofax
https://github.com/mofax @aserrabl https://github.com/aserrabl
@SarantopoulosKon https://github.com/SarantopoulosKon.

I assume you are using a version of node < 8.6, right?
Source: https://node.green/#ES2018-features-object-rest-spread-properties

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/styled-components/jest-styled-components/issues/192#issuecomment-429563705,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFoKCvLIt4x3lFU1qnisUUwYc8QPp79eks5uki4TgaJpZM4W4Uh_
.

Me too @MicheleBertoli

The package.json can/should define the engines field to show a warning if a supported version of node is not installed.

https://docs.npmjs.com/files/package.json#engines

Alternatively (and preferably), toHaveStyleRule.js should be updated to not use a rest spread prop. Node 6 is still supported until April 2019, so it's probably best if we continue support for that as well.

I ran into this too, for a quick temporary fix you can just tell jest to transform this package by adding the following line to your jest config:
"transformIgnorePatterns": ["/node_modules\/(?!(jest-styled-components)\/).*/"]

Was this page helpful?
0 / 5 - 0 ratings