Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fails after upgrading to 0.56.0 - babel 7 #20141

Closed
fhadsheikh opened this issue Jul 11, 2018 · 2 comments
Closed

Test fails after upgrading to 0.56.0 - babel 7 #20141

fhadsheikh opened this issue Jul 11, 2018 · 2 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@fhadsheikh
Copy link

fhadsheikh commented Jul 11, 2018

Environment

React Native Environment Info:
System:
OS: macOS High Sierra 10.13.3
CPU: x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Memory: 39.36 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 8.0.0 - ~/.nvm/versions/node/v8.0.0/bin/node
Yarn: 1.7.0 - ~/.nvm/versions/node/v8.0.0/bin/yarn
npm: 5.4.1 - ~/.nvm/versions/node/v8.0.0/bin/npm
Watchman: 4.7.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
Android SDK:
Build Tools: 26.0.2
IDEs:
Android Studio: 3.1 AI-173.4670197
Xcode: 9.4/9F1027a - /usr/bin/xcodebuild
npmPackages:
react: 16.4.1 => 16.4.1
react-native: 0.56.0 => 0.56.0
npmGlobalPackages:
create-react-native-app: 1.0.0
eslint-plugin-react-native: 3.0.1
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7

Description

Tests are failing with:

TypeError: this._instance.render is not a function

Tests only fail when NOT using arrow function.

Package.json

{
  "name": "TestApp56",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.4.1",
    "react-native": "0.56.0"
  },
  "devDependencies": {
    "@babel/core": "^7.0.0-beta.52",
    "babel-core": "^7.0.0-0",
    "babel-jest": "^23.4.0",
    "babel-preset-react-native": "^5.0.1",
    "jest": "^23.4.0",
    "react-test-renderer": "16.4.1",
    "regenerator-runtime": "^0.12.0"
  },
  "jest": {
    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!react-native).+\\.js$"
    ]
  }
}

Fails

import React, { Component } from 'react';
import { Text } from 'react-native';
import ShallowRenderer from 'react-test-renderer/shallow';

class Terms extends Component {
    render() {
        return <Text>Hello</Text>
    }
}


describe('Terms', () => {
    let props;
    let renderer;
    const render = () => {
        if (! renderer) {
            renderer = new ShallowRenderer();
            renderer.render(<Terms {...props} />);
        }
        return renderer;
    };

    it('renders when terms ARE required', () => {
        const rendered = render().getRenderOutput();
        expect(rendered).toBeTruthy();
    });
});

Passes

import React, { Component } from 'react';
import { Text } from 'react-native';
import ShallowRenderer from 'react-test-renderer/shallow';

class Terms extends Component {
    render = () => <Text>Hello</Text>
}


describe('Terms', () => {
    let props;
    let renderer;
    const render = () => {
        if (! renderer) {
            renderer = new ShallowRenderer();
            renderer.render(<Terms {...props} />);
        }
        return renderer;
    };

    it('renders when terms ARE required', () => {
        const rendered = render().getRenderOutput();
        expect(rendered).toBeTruthy();
    });
});

Repro repo

link here

@kelset
Copy link
Contributor

kelset commented Jul 13, 2018

For issues related to jest/testing refer to #19859

@kelset kelset closed this as completed Jul 13, 2018
@fhadsheikh
Copy link
Author

fhadsheikh commented Jul 13, 2018

@kelset The issue you referred me to is different and locked. That issue is Plugin 0 specified in "project/node_modules/babel-preset-react-native/index.js" provided an invalid property of "default"

I could run tests in Jest. The issue is that non arrow functions are undefined.

@facebook facebook locked as resolved and limited conversation to collaborators Jul 18, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

3 participants