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.

Example jest testing fails out of the box

See original GitHub issue

When I run npm test after installing the example test in App.test.js is discovered and fails.

I’m running OSX 10.13.6, npm 6.4.1, node 10.11.0

Steps to reproduce

  1. Go to root directory in terminal and run npm test, select a option to run all tests from the command line prompt

Expected result

Tests should run and pass.

Actual result

The test is discovered and fails:

  ● Test suite failed to run

    /Users/jfunk/Documents/Code/git/RN-PVP/node_modules/redux-persist/es/integration/react.js:9
    import React, { PureComponent } from 'react'; // eslint-disable-line import/no-unresolved
           ^^^^^

    SyntaxError: Unexpected identifier

      4 | import { Provider } from 'react-redux';
      5 | import { Router, Stack } from 'react-native-router-flux';
    > 6 | import { PersistGate } from 'redux-persist/es/integration/react';
        | ^
      7 |
      8 | import { Root, StyleProvider } from 'native-base';
      9 | import getTheme from '../../native-base-theme/components';

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
      at Object.<anonymous> (src/native/index.js:6:1)

Test Suites: 1 failed, 1 total

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
j-funkcommented, Dec 29, 2018

I eventually worked around this with:

“jest”: { “preset”: “jest-expo”, “transformIgnorePatterns”: [] },

From this issue.

0reactions
j-funkcommented, Jan 13, 2019

Also add jest.useFakeTimers(); to the test file.

import React from 'react';
import renderer from 'react-test-renderer';
import App from './App';

jest.useFakeTimers();

it('renders without crashing', () => {
  const rendered = renderer.create(<App />).toJSON();
  expect(rendered).toBeTruthy();
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest: mocking console.error - tests fails - Stack Overflow
It's when I test with enzyme/react that I hit this wall after the first test. Sample App.js: import React, { Component } from...
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 >
Jest · Delightful JavaScript Testing
Jest aims to work out of the box, config free, on most JavaScript projects. Snapshots. Make tests which keep track of large objects...
Read more >
Jest testing: Top features and how to use them - LogRocket Blog
Out-of-the-box ease​​ Some examples: Add coverage when invoking Jest to get coverage reports from your tests with the ability to choose between a ......
Read more >
Jest Testing Tutorial: 5 Easy Steps - Testim Blog
Jest Testing: A Helpful, Introductory Tutorial · its definition · very fast to execute · Zero config: “Jest aims to work out of...
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