-
Notifications
You must be signed in to change notification settings - Fork 9
/
portal.spec.jsx
41 lines (33 loc) · 1.14 KB
/
portal.spec.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { mount } from 'enzyme'
import React from 'react'
import Portal from './portal'
describe('<Portal />', () => {
it('creates a div with a unique id', () => {
Portal.idNum = 0
mount(<Portal />)
mount(<Portal />)
expect(document.getElementById('portal-0')).to.exist
expect(document.getElementById('portal-1')).to.exist
document.getElementById('portal-0').remove()
document.getElementById('portal-1').remove()
})
it('renders children', () => {
Portal.idNum = 0
mount(<Portal><div className='foo' /></Portal>)
expect(document.querySelector('.foo')).to.exist
document.getElementById('portal-0').remove()
})
it('removes the portal div on unmount', () => {
Portal.idNum = 0
const component = mount(<Portal />)
component.unmount()
expect(document.getElementById('portal-0')).not.to.exist
})
it('gracefully handles the portal div no longer existing on unmount', () => {
Portal.idNum = 0
const component = mount(<Portal />)
document.getElementById('portal-0').remove()
component.unmount() // should not error
expect(document.getElementById('portal-0')).not.to.exist
})
})