styled-components / jest-styled-components

🔧 💅 Jest utilities for Styled Components
MIT License
1.59k stars 145 forks source link

Nullish coalescing operator throwing error #393

Closed DanielJWagener closed 3 years ago

DanielJWagener commented 3 years ago

I don't know if this package should try to handle this or not, but here goes. If I write a style that uses the nullish coalescing operator, Jest complains:

padding-left: ${(props) => props.paddingLeft ?? props.theme.smallSpace};
undefined:1:1043: property missing ':'

// ...

at error (node_modules/jest-styled-components/node_modules/css/lib/parse/index.js:62:15)
at getCSS (node_modules/jest-styled-components/src/utils.js:32:26)
at getStyle (node_modules/jest-styled-components/src/styleSheetSerializer.js:75:15)
at Object.print (node_modules/jest-styled-components/src/styleSheetSerializer.js:135:19)
at printPlugin (node_modules/pretty-format/build/index.js:316:16)
at prettyFormat (node_modules/pretty-format/build/index.js:532:16)
at __EXTERNAL_MATCHER_TRAP__ (node_modules/expect/build/index.js:342:30)
at Object.toMatchSnapshot (node_modules/expect/build/index.js:343:15)
at Object.<anonymous> (/*path__to__my__snapshot__test.js:14:20*/)

It works fine if I replace the ?? with a ||. Both props.paddingLeft and props.theme.smallSpace are non-empty strings in this test.

DanielJWagener commented 3 years ago

Never mind, this was actually due to a different bug in our codebase