question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Need help with jest

See original GitHub issue

Hi! When I run test I recive this error:

 FAIL  src/Button/tests/Button.test.tsx
  ● Test suite failed to run

    `css` template literal evaluated at runtime!

       6 | };
       7 |
    >  8 | const styles = css`
         |             ^
       9 |   .button{
      10 |     color: red;
      11 |

      at css (node_modules/astroturf/runtime/styled.js:98:9)
      at Object.<anonymous> (src/Button/Button.tsx:8:13)
      at Object.<anonymous> (src/Button/tests/Button.test.tsx:3:1)

I think I need to configure transform prop in jest config or modify babel config with test env, but I don’t know exactly how. Any ideas?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
ivancuriccommented, Apr 25, 2019

For using astroturf with jest, I suggest mocking the module unless you are specifically trying to test the styling

You add a __mocks__/astroturf.js to jest rootDir and it will automatically mock out the astroturf package.

// __mocks__/astroturf.js

const styled = (Component) => () => (props) => <Component {...props} />

export const css = () => {}

export default styled

You can leave off the styled version and use the babel plugin as well if you do want to run the transforms in your tests. I’m not sure what the error your getting is about but if you can put together a quick reproduction repo i’ll be happy to take a look!

Should be export const css = () => ({});

1reaction
dreykscommented, Sep 25, 2019

you’re reading my mind 😄 inline option was the first thing i thought of but then backed off so as not to drag css-handling into the mix

i think this might be a good candidate for astroturf-jest transform though

Read more comments on GitHub >

github_iconTop Results From Across the Web

Need help? - Jest
Need help ? Jest is worked on by a team of volunteers in their spare time. You can find out ways to talk...
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 >
What Is Jest – A Tutorial on How to Use Jest - LambdaTest
Jest comes with all of the features that are required in a modern testing framework. Built-in modules provide good support for plugins, and...
Read more >
Jest Tutorial for Beginners: Getting Started With JavaScript ...
Jest is a JavaScript test runner, that is, a JavaScript library for creating, running, and structuring tests. Jest ships as an NPM package,...
Read more >
Jest Testing Tutorial: 5 Easy Steps - Testim Blog
In summary, this means that Jest offers a test runner, assertion library, CLI tool, and great support for different mocking techniques.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found