How to unit test the component with Translation?

安稳与你 提交于 2020-01-25 20:27:07

问题


I have the following react component class:

import React, { Component } from "react";
import { withTranslation } from "react-i18next";

class XYZ extends Component {
    constructor(props) {
    super(props);
    this.state = {
    };
  }

  .....
  .....


  render() {
    const { t } = this.props;

    return (

        ..... 
    );
  }
}

export default withTranslation()(XYZ);

When I am trying to unit test this component and mount this component using enzyme, I am getting following error:

This is what I am trying to do:

const wrapper = mount(<ManageOrders />);

And this is the eror:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Any idea how can I fix it? And why I am getting this error. I feel like this is something to do with Translation library, because when I do export class XYZ extends Component, it goes inside and fail at the line where I am trying to do translation.

来源:https://stackoverflow.com/questions/59773467/how-to-unit-test-the-component-with-translation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!