Unit testing 单元测试组件参考

Unit testing 单元测试组件参考,unit-testing,reactjs,enzyme,Unit Testing,Reactjs,Enzyme,现在,一个组件看起来如下所示: class Notification extends Component { constructor(props, context) { super(props,context); } render() { return (<NotificationSystem ref="notificationSystem"/>); } } export defau

现在,一个组件看起来如下所示:

  class Notification extends Component {
      constructor(props, context) {
        super(props,context);
      }


      render() {
        return (<NotificationSystem ref="notificationSystem"/>);
      }
   }

   export default Notification;
我的渲染组件是:

function renderComponent(ComponentClass, props = {}, state = {}) {
    let store = createStore(reducer, state);
    return (
     <Provider store={store}>
        <ComponentClass { ...props } /> 
     </Provider>     
    );
}

知道如何正确地测试组件是否可引用吗?

Hi!你找到答案了吗?嗨!你找到答案了吗?
function renderComponent(ComponentClass, props = {}, state = {}) {
    let store = createStore(reducer, state);
    return (
     <Provider store={store}>
        <ComponentClass { ...props } /> 
     </Provider>     
    );
}
Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded