Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
invokeSetStateCallback(instance, callback) {
// React in >= 15.4, and < 16 pass undefined to a setState callback
const invoke = ifReact(
'^15.4',
() => { callback.call(instance, undefined); },
() => { super.invokeSetStateCallback(instance, callback); },
);
invoke();
}
invokeSetStateCallback(instance, callback) {
// React in >= 15.4, and < 16 pass undefined to a setState callback
const invoke = ifReact(
'^15.4',
() => { callback.call(instance, undefined); },
() => { super.invokeSetStateCallback(instance, callback); },
);
invoke();
}
}
const itIfReact = (version, ...args) => ifReact(version, () => it(...args), () => it.skip(...args));
const itIfReact = (version, ...args) => ifReact(version, () => it(...args), () => it.skip(...args));
ReactDOM.unmountComponentAtNode(document.getElementById('root'));
document.body.innerHTML = '';
});
ifReact('>= 16', test, test.skip)('should not mount portal by default', () => {
ReactDOM.render(
{({ portal }) => portal('Foo')},
document.getElementById('root')
);
expect(document.body.firstChild.outerHTML).toBe('<div id="root"></div>');
expect(document.body.lastChild.outerHTML).toBe(
document.body.lastChild.outerHTML
);
});
ifReact('< 16', test, test.skip)('should not mount portal by default', () => {
ReactDOM.render(
{({ portal }) => portal('Foo')},
document.getElementById('root')
);
expect(document.body.firstChild.outerHTML).toBe(
'<div id="root"></div>'
);
expect(document.body.lastChild.outerHTML).toBe(
document.body.lastChild.outerHTML
);
});
ifReact('>= 16', test, test.skip)(
'should mount portal by default with defaultOpen',
() => {
ReactDOM.render(
import React from 'react';
import ReactDOM from 'react-dom';
import ifReact from 'enzyme-adapter-react-helper/build/ifReact';
import PortalWithState from '../src/PortalWithState';
beforeEach(() => {
document.body.innerHTML = '<div id="root"></div>';
});
afterEach(() => {
ReactDOM.unmountComponentAtNode(document.getElementById('root'));
document.body.innerHTML = '';
});
ifReact('>= 16', test, test.skip)('should not mount portal by default', () => {
ReactDOM.render(
{({ portal }) => portal('Foo')},
document.getElementById('root')
);
expect(document.body.firstChild.outerHTML).toBe('<div id="root"></div>');
expect(document.body.lastChild.outerHTML).toBe(
document.body.lastChild.outerHTML
);
});
ifReact('< 16', test, test.skip)('should not mount portal by default', () => {
ReactDOM.render(
{({ portal }) => portal('Foo')},
document.getElementById('root')
);
expect(document.body.firstChild.outerHTML).toBe(
this.setState(prevState => ({
isPortalTwoActive: !prevState.isPortalTwoActive
}))
}
>
Toggle
{this.state.isPortalTwoActive && (
<p>This thing was portaled with custom node!</p>
)}
<h2>PortalWithState</h2>
{ifReact(
'< 16.2',
({ openPortal, closePortal, isOpen, portal }) => (
<div>
<button>
Open Portal {isOpen && '(this counts as an outside click)'}
</button>
{portal(
<p>
This is more advanced Portal. It handles its own state.{' '}
<button>Close me!</button>, hit ESC or
click outside of me.
</p>
)}
</div>
),
({ openPortal, closePortal, isOpen, portal }) => (