【发布时间】:2020-01-23 18:42:15
【问题描述】:
我已经创建了我的自定义组件 NumberInput 字段。我是编写测试用例的新手,所以我只是尝试编写一个简单的测试用例并希望成功执行它。
这是我的组件
import React from 'react';
import PropTypes from 'prop-types';
import NumberFormat from 'react-number-format';
import TextField from 'components/TextField';
function CustomInput(props) {
return <TextField {...props} />;
}
function NumberInput(props) {
const { onChange, ...otherProps } = props;
return (
<NumberFormat
thousandSeparator
decimalSeparator="."
decimalScale={2}
{...otherProps}
customInput={CustomInput}
onValueChange={values => {
const { value } = values;
onChange(value);
}}
/>
);
}
NumberInput.propTypes = {
onChange: PropTypes.func,
};
export default NumberInput;
我正在尝试为此编写一个测试用例
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import { NumberInput } from '../index';
describe('<NumberInputField />', () => {
it('Expect to have unit tests specified', () => {
const { container } = render(<NumberInput />);
const NumberFormat = container.firstChild
fireEvent.change(NumberFormat, { target: { value: 10 } });
expect(NumberFormat.value).toBe(10);
//expect(true).toEqual(false);
});
});
我正在尝试使用
编写测试用例开玩笑
测试库/反应
【问题讨论】:
标签: reactjs unit-testing jestjs react-testing-library