2018-12-07 20:02:01 +08:00
|
|
|
/* eslint-disable react/prefer-stateless-function */
|
2017-01-13 21:52:48 +08:00
|
|
|
import React from 'react';
|
2018-12-05 19:12:18 +08:00
|
|
|
import { mount } from 'enzyme';
|
2017-01-13 21:52:48 +08:00
|
|
|
import Form from '..';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2017-01-13 21:52:48 +08:00
|
|
|
|
|
|
|
describe('Form', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Form);
|
|
|
|
mountTest(Form.Item);
|
|
|
|
|
2017-01-13 21:52:48 +08:00
|
|
|
it('hideRequiredMark', () => {
|
2018-12-07 20:02:01 +08:00
|
|
|
const wrapper = mount(<Form hideRequiredMark />);
|
2018-12-05 19:12:18 +08:00
|
|
|
expect(wrapper.find('form').hasClass('ant-form-hide-required-mark')).toBe(true);
|
2017-01-13 21:52:48 +08:00
|
|
|
});
|
2017-10-31 13:56:43 +08:00
|
|
|
|
|
|
|
describe('wrappedComponentRef', () => {
|
|
|
|
it('warns on functional component', () => {
|
2017-11-06 17:34:14 +08:00
|
|
|
if (process.env.REACT === '15') {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-31 13:56:43 +08:00
|
|
|
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
const TestForm = () => <Form />;
|
|
|
|
const Wrapped = Form.create()(TestForm);
|
|
|
|
mount(<Wrapped wrappedComponentRef={() => {}} />);
|
|
|
|
expect(spy).toHaveBeenCalled();
|
|
|
|
spy.mockReset();
|
|
|
|
spy.mockRestore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('get component ref', () => {
|
2018-12-07 20:02:01 +08:00
|
|
|
class TestForm extends React.Component {
|
|
|
|
// eslint-disable-line
|
2017-10-31 13:56:43 +08:00
|
|
|
render() {
|
|
|
|
return <Form />;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const Wrapped = Form.create()(TestForm);
|
|
|
|
let form;
|
2018-12-07 20:02:01 +08:00
|
|
|
mount(
|
|
|
|
<Wrapped
|
|
|
|
wrappedComponentRef={node => {
|
|
|
|
form = node;
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
2017-10-31 13:56:43 +08:00
|
|
|
expect(form).toBeInstanceOf(TestForm);
|
|
|
|
});
|
|
|
|
});
|
2017-01-13 21:52:48 +08:00
|
|
|
});
|