Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should render one portal', () => {
const container = createNodeElement('div');
const portalContainer = createNodeElement('div');
render(
<div>{createPortal(<div>portal</div>, portalContainer)}</div>,
container
);
jest.runAllTimers();
expect(container.childNodes[0].tagName).toBe('DIV');
expect(portalContainer.childNodes[0].childNodes[0].data).toBe('portal');
unmountComponentAtNode(container);
expect(container.childNodes.length).toBe(0);
expect(portalContainer.childNodes.length).toBe(0);
});
it('findDOMNode should reject unmounted objects with render func', function() {
class Foo extends Component {
render() {
return <div>;
}
}
let container = createNodeElement('div');
var inst = render(, container);
unmountComponentAtNode(container);
expect(() => findDOMNode(inst)).toThrowError(
'findDOMNode: find on an unmounted component.'
);
});
</div>
componentWillUnmount() {
unmountComponentAtNode(this.props.container);
}
componentDidUpdate(prevProps) {
if (prevProps.container !== this.props.container) {
unmountComponentAtNode(prevProps.container);
}
this.renderPortal();
}