Switching to use forwardRef
This commit is contained in:
parent
b9f6766a66
commit
3916d63f2d
@ -146,7 +146,7 @@ class App extends React.PureComponent {
|
|||||||
<p>Sample warning message</p>
|
<p>Sample warning message</p>
|
||||||
</Message>
|
</Message>
|
||||||
{ image && <div className={ style.render }>
|
{ image && <div className={ style.render }>
|
||||||
<SVG data={ image } imageRef={ this.image }/>
|
<SVG data={ image } ref={ this.image }/>
|
||||||
</div> }
|
</div> }
|
||||||
</React.Fragment>;
|
</React.Fragment>;
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,10 @@ import React from 'react';
|
|||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import { App } from 'components/App';
|
import { App } from 'components/App';
|
||||||
import renderImage from 'components/SVG';
|
|
||||||
import { translate } from '__mocks__/i18n';
|
import { translate } from '__mocks__/i18n';
|
||||||
|
|
||||||
describe('App', () => {
|
describe('App', () => {
|
||||||
test('rendering', () => {
|
test('rendering', () => {
|
||||||
renderImage.mockReturnValue('Testing image');
|
|
||||||
const component = shallow(
|
const component = shallow(
|
||||||
<App t={ translate }/>
|
<App t={ translate }/>
|
||||||
);
|
);
|
||||||
|
@ -34,15 +34,14 @@ const render = (data, extraProps) => {
|
|||||||
children.length === 1 ? children[0] : children);
|
children.length === 1 ? children[0] : children);
|
||||||
};
|
};
|
||||||
|
|
||||||
const SVG = ({ data, imageRef: ref }) => render(data, { ref });
|
const SVG = React.forwardRef(({ data }, ref) => render(data, { ref }));
|
||||||
|
|
||||||
SVG.propTypes = {
|
SVG.propTypes = {
|
||||||
data: PropTypes.shape({
|
data: PropTypes.shape({
|
||||||
type: PropTypes.oneOf(Object.keys(nodeTypes)).isRequired,
|
type: PropTypes.oneOf(Object.keys(nodeTypes)).isRequired,
|
||||||
props: PropTypes.object,
|
props: PropTypes.object,
|
||||||
children: PropTypes.array
|
children: PropTypes.array
|
||||||
}).isRequired,
|
}).isRequired
|
||||||
imageRef: PropTypes.func
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SVG;
|
export default SVG;
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow, mount } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import SVG from 'components/SVG';
|
import SVG from 'components/SVG';
|
||||||
import Pin from './Pin';
|
|
||||||
|
|
||||||
describe('SVG', () => {
|
describe('SVG', () => {
|
||||||
test('rendering', async () => {
|
test('rendering', async () => {
|
||||||
@ -94,16 +93,4 @@ describe('SVG', () => {
|
|||||||
);
|
);
|
||||||
expect(component).toMatchSnapshot();
|
expect(component).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('imageRef prop', () => {
|
|
||||||
let image;
|
|
||||||
const imageRef = element => image = element;
|
|
||||||
const data = {
|
|
||||||
type: 'Pin'
|
|
||||||
};
|
|
||||||
mount(
|
|
||||||
<SVG data={ data } imageRef={ imageRef }/>
|
|
||||||
);
|
|
||||||
expect(image).toBeInstanceOf(Pin);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user