问题
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