Я новичок в модульном тестировании.
Ниже находится компонент
import React from 'react';
import PropTypes from "prop-types";
import {Textfit} from 'react-textfit'; //This will fit the text how big or small it is.
class DisplayPanel extends React.Component {
render() {
return (
<Textfit className="calculator-display">{this.props.value}</Textfit>
);
}
}
DisplayPanel.propTypes = {
value: PropTypes.string,
};
export default DisplayPanel
Я хочу написать тестовый сценарий в отношении
<Textfit className="calculator-display">{this.props.value}</Textfit>
, который проверяет наличие компонентов, имеет настройку.
Как я могу сделать это с шуткой и энзимом?
Я попробовал код для тестов, как показано ниже:
import React from "react";
import { shallow } from "enzyme";
import DisplayPanel from "../components/DisplayPanel";
import { Textfit } from "react-textfit";
describe("Display Panel", () => {
let wrapper;
beforeEach(() => (wrapper = shallow(<DisplayPanel/>)));
it("should render correctly", () => expect(wrapper).toMatchSnapshot());
it("should render a Textfit component", () => {
expect(wrapper.containsMatchingElement(<Textfit />)).toEqual(true);
});
//what should come here
it("renders the value", () => {
//expect(wrapper.text()).toEqual('0');
});
});