Reactjs React本机呈现程序中的Ref为null。单元测试中的create()调用未通过我的测试

Reactjs React本机呈现程序中的Ref为null。单元测试中的create()调用未通过我的测试,reactjs,unit-testing,react-native,jestjs,enzyme,Reactjs,Unit Testing,React Native,Jestjs,Enzyme,我正在使用 "react": "^16.4.0", "jest": "^22.4.4", 然后在我的组件中,我使用react native下拉警报 import DropdownAlert from 'react-native-dropdownalert'; 在我的渲染函数中,我把它放在了最底部 <DropdownAlert ref={this.dropdownRef} /> 然后,我在渲染之前用这一行触发下拉列表。这是导致单元测试中出现问题的那一行

我正在使用

"react": "^16.4.0",
"jest": "^22.4.4",
然后在我的组件中,我使用react native下拉警报

 import DropdownAlert from 'react-native-dropdownalert';
在我的渲染函数中,我把它放在了最底部

  <DropdownAlert
      ref={this.dropdownRef}
    />
然后,我在渲染之前用这一行触发下拉列表。这是导致单元测试中出现问题的那一行

this.dropdownRef.current.alertWithType('error', 'Error', this.props.firebaseInfo.errorMessage);
这是我的单元测试

import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';
import { SignUp } from '../SignUp';
import Enzyme, { mount, shallow } from 'enzyme'


function createNodeMock() {

  return {
    DropdownAlert: {
      alertWithType() {

      }
    },
    current: {
      DropdownAlert: {
        alertWithType() {}
      }
    },
    alertWithType() {}
  }
}


describe('Sign up page component', () => {
  it('sign up renders correctly', () => {

    const props = {
      actions: {},
      userInfo: {},
      firebaseInfo: {},
    };

    const tree = renderer.create(<SignUp {...props}/>, {createNodeMock}).toJSON();

    expect(tree).toMatchSnapshot();
  });
});
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';
import { SignUp } from '../SignUp';
import Enzyme, { mount, shallow } from 'enzyme'


function createNodeMock() {

  return {
    DropdownAlert: {
      alertWithType() {

      }
    },
    current: {
      DropdownAlert: {
        alertWithType() {}
      }
    },
    alertWithType() {}
  }
}


describe('Sign up page component', () => {
  it('sign up renders correctly', () => {

    const props = {
      actions: {},
      userInfo: {},
      firebaseInfo: {},
    };

    const tree = renderer.create(<SignUp {...props}/>, {createNodeMock}).toJSON();

    expect(tree).toMatchSnapshot();
  });
});
TypeError: Cannot read property 'alertWithType' of null