Skip to content

Can't run tests with React Native 0.56 #20052

Closed
@victorlevasseur

Description

@victorlevasseur

Environment

React Native Environment Info:
System:
OS: Linux 4.15 Ubuntu 18.04 LTS (Bionic Beaver)
CPU: x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Memory: 3.08 GB / 15.39 GB
Shell: 4.4.19 - /bin/bash
Binaries:
Node: 8.10.0 - /usr/bin/node
Yarn: 1.5.1 - /usr/local/bin/yarn
npm: 6.1.0 - /usr/local/bin/npm
npmPackages:
react: 16.4.1 => 16.4.1
react-native: 0.56.0 => 0.56.0
npmGlobalPackages:
react-native-cli: 2.0.1

Description

When launching the tests with npm test, I get the following output :

[email protected] test /home/victor/Wedoogift/JsProject
> jest

 FAIL  ./App.test.js
  ● Test suite failed to run

    SyntaxError: /home/victor/Wedoogift/JsProject/node_modules/react-native/Libraries/Utilities/Platform.ios.js: Unexpected token, expected "{" (35:17)

      33 |     return constants ? constants.interfaceIdiom === 'tv' : false;
      34 |   },
    > 35 |   get isTesting(): boolean {
         |                  ^
      36 |     const constants = NativeModules.PlatformConstants;
      37 |     return constants && constants.isTesting;
      38 |   },

      at Parser.raise (node_modules/@babel/core/node_modules/babylon/lib/index.js:776:15)
      at Parser.unexpected (node_modules/@babel/core/node_modules/babylon/lib/index.js:2079:16)
      at Parser.expect (node_modules/@babel/core/node_modules/babylon/lib/index.js:2067:28)
      at Parser.parseBlock (node_modules/@babel/core/node_modules/babylon/lib/index.js:4488:10)
      at Parser.parseFunctionBody (node_modules/@babel/core/node_modules/babylon/lib/index.js:3754:24)
      at Parser.parseFunctionBodyAndFinish (node_modules/@babel/core/node_modules/babylon/lib/index.js:3734:10)
      at Parser.parseMethod (node_modules/@babel/core/node_modules/babylon/lib/index.js:3686:10)
      at Parser.parseObjectMethod (node_modules/@babel/core/node_modules/babylon/lib/index.js:3609:12)
      at Parser.parseObjPropValue (node_modules/@babel/core/node_modules/babylon/lib/index.js:3644:21)
      at Parser.parseObj (node_modules/@babel/core/node_modules/babylon/lib/index.js:3555:12)

Test Suites: 1 failed, 1 total
Tests:       0 total

Reproducible Demo

It just consists of the default app obtained with "react-native init" and with an "App.test.js" file containing the following code :

import * as React from 'react';

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

test('renders correctly', () => {
  const tree = renderer.create(<App />).toJSON();
  expect(tree).toMatchSnapshot();
});

Note: I had to add babel-core^7.0.0-beta3 to be able to start the tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions