ant-design/components/form/__tests__/index.test.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-12-07 20:02:01 +08:00
/* eslint-disable react/prefer-stateless-function */
import React from 'react';
import { mount } from 'enzyme';
import Form from '..';
describe('Form', () => {
it('hideRequiredMark', () => {
2018-12-07 20:02:01 +08:00
const wrapper = mount(<Form hideRequiredMark />);
expect(wrapper.find('form').hasClass('ant-form-hide-required-mark')).toBe(true);
});
2017-10-31 13:56:43 +08:00
describe('wrappedComponentRef', () => {
it('warns on functional component', () => {
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);
});
});
});