mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 03:29:39 +08:00
Add form wrappedComponentRef test
This commit is contained in:
parent
7ff7519207
commit
8c904de7d4
@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { shallow, mount } from 'enzyme';
|
||||
import Form from '..';
|
||||
|
||||
describe('Form', () => {
|
||||
@ -9,4 +9,28 @@ describe('Form', () => {
|
||||
);
|
||||
expect(wrapper.hasClass('ant-form-hide-required-mark')).toBe(true);
|
||||
});
|
||||
|
||||
describe('wrappedComponentRef', () => {
|
||||
it('warns on functional component', () => {
|
||||
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', () => {
|
||||
class TestForm extends React.Component { // eslint-disable-line
|
||||
render() {
|
||||
return <Form />;
|
||||
}
|
||||
}
|
||||
const Wrapped = Form.create()(TestForm);
|
||||
let form;
|
||||
mount(<Wrapped wrappedComponentRef={node => form = node} />);
|
||||
expect(form).toBeInstanceOf(TestForm);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user