Jest ошибка при тестировании React Native с Jest - PullRequest
0 голосов
/ 13 марта 2019

У меня возникла проблема с Jest при тестировании компонента приложения React Native.Несколько других компонентов уже проходят тестирование в соответствии с ожиданиями с той же конфигурацией Jest, но этот вызывает странную ошибку, поэтому вам нужна помощь, пожалуйста, здесь.

Компонент входа

import React, { Component, Fragment } from "react";
import { func } from "prop-types";
import { View, Text } from "react-native";
import { TextInput, Button } from "react-native-paper";

import { STYLE_CONSTANTS } from "../../config/styles";
import styles from "./styles";
import { loginScreenText } from "./helpers";

class SignIn extends Component {
  state = {
    isLoading: false
  };

  render() {
    const { isLoading } = this.state;
    const { showAppAction } = this.props;
    return (
      <Fragment>
        <View style={styles.signInContainer}>
          <Text style={styles.oAuthHeading}>
            {loginScreenText.oAuthHeading}
          </Text>
          <View style={styles.spacer} />
          <Button
            icon={require("../../assets/images/facebook.png")}
            mode="contained"
            loading={isLoading}
            color={STYLE_CONSTANTS.COLORS.FACEBOOK}
            style={styles.facebookButton}
            onPress={() => showAppAction()}
          >
            {loginScreenText.facebookButton}
          </Button>
          <View style={styles.spacer} />
          <Button
            icon={require("../../assets/images/google.png")}
            mode="contained"
            loading={isLoading}
            color={STYLE_CONSTANTS.COLORS.GOOGLE}
            style={styles.googleButton}
            onPress={() => showAppAction()}
          >
            {loginScreenText.googleButton}
          </Button>
        </View>
      </Fragment>
    );
  }
}

SignIn.propTypes = {
  showAppAction: func
};

export default SignIn;

Тест входаfile

import "react-native";
import React from "react";
import ShallowRenderer from "react-test-renderer/shallow";

import SignIn from "../containers/SignIn";

test('renders SignIn component correctly', () => {
  const renderer = new ShallowRenderer();
  renderer.render(<SignIn showAppAction={jest.fn()} />);
  const wrapper = renderer.getRenderOutput();
  expect(wrapper).toMatchSnapshot();
});

Jest config в package.json

"jest": {
  "preset": "react-native",
  "collectCoverage": true,
  "coverageDirectory": "__coverage__",
  "transform": {
    "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
  },
  "transformIgnorePatterns": [
    "node_modules/(?!react-native|native-base|react-navigation|react-native-fabric|react-native-paper)"
  ]
},

Наконец скриншот ошибки

jest error

1 Ответ

0 голосов
/ 19 марта 2019

Я смог решить эту проблему, следуя обсуждению здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...