Skip to content

Commit

Permalink
(tests) - add additional test for createPortal -> normal vnode
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jul 26, 2019
1 parent 1df2490 commit 9599374
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions compat/test/browser/portals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,30 @@ describe('Portal', () => {
expect(spyParent).to.be.calledOnce;
expect(spy).to.be.calledOnce;
});

it('should switch between non portal and portal node', () => {
let toggle;
const Modal = ({ children, open }) => open
? createPortal(<div>{children}</div>, scratch)
: <div>Closed</div>;

const App = () => {
const [open, setOpen] = useState(false);
toggle = setOpen.bind(this, (x) => !x);
return (
<div>
<button onClick={() => setOpen(!open)}>Show</button>
{open ? 'Open' : 'Closed'}
<Modal open={open}>Hello</Modal>
</div>
);
};

render(<App />, scratch);
expect(scratch.innerHTML).to.equal('<div><button>Show</button>Closed<div>Closed</div></div>');

toggle();
rerender();
expect(scratch.innerHTML).to.equal('<div>Hello</div><div><button>Show</button>Open</div>');
});
});

0 comments on commit 9599374

Please sign in to comment.