From 797bf4c407862e31968fdaf694daa0bac77070da Mon Sep 17 00:00:00 2001 From: emyarod Date: Thu, 27 Feb 2020 21:53:07 -0600 Subject: [PATCH] test: clean up container div --- .../src/components/Checkbox/Checkbox-test.js | 11 ++++++++++- .../ComposedModal/ComposedModal-test.js | 15 +++++++++++---- .../react/src/components/Select/Select-test.js | 11 ++++++++++- .../TextInput/ControlledPasswordInput-test.js | 11 ++++++++++- .../src/components/TextInput/TextInput-test.js | 11 ++++++++++- 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/packages/react/src/components/Checkbox/Checkbox-test.js b/packages/react/src/components/Checkbox/Checkbox-test.js index a432799a0f6e..e92a721daf47 100644 --- a/packages/react/src/components/Checkbox/Checkbox-test.js +++ b/packages/react/src/components/Checkbox/Checkbox-test.js @@ -110,6 +110,8 @@ describe('Checkbox', () => { }); describe('refs', () => { + let container; + it('should accept refs', () => { class MyComponent extends React.Component { constructor(props) { @@ -131,7 +133,7 @@ describe('refs', () => { ); } } - const container = document.createElement('div'); + container = document.createElement('div'); container.id = 'container'; document.body.appendChild(container); const wrapper = mount(, { @@ -162,6 +164,13 @@ describe('refs', () => { const wrapper = mount(); expect(wrapper.find('input').getDOMNode().indeterminate).toBe(true); }); + + afterEach(() => { + if (container && container.parentNode) { + container.parentNode.removeChild(container); + } + container = null; + }); }); describe('CheckboxSkeleton', () => { diff --git a/packages/react/src/components/ComposedModal/ComposedModal-test.js b/packages/react/src/components/ComposedModal/ComposedModal-test.js index e29dca8174c1..540b0a5e4ce2 100644 --- a/packages/react/src/components/ComposedModal/ComposedModal-test.js +++ b/packages/react/src/components/ComposedModal/ComposedModal-test.js @@ -153,6 +153,8 @@ describe('', () => { }); describe('', () => { + let container; + it('renders', () => { const wrapper = mount(); expect(wrapper).toMatchSnapshot(); @@ -214,7 +216,7 @@ describe('', () => { }); it('should focus on the primary actionable button in ModalFooter by default', () => { - const container = document.createElement('div'); + container = document.createElement('div'); container.id = 'container'; document.body.appendChild(container); mount( @@ -226,11 +228,10 @@ describe('', () => { expect( document.activeElement.classList.contains(`${prefix}--btn--primary`) ).toEqual(true); - document.body.removeChild(container); }); it('should focus on the element that matches selectorPrimaryFocus', () => { - const container = document.createElement('div'); + container = document.createElement('div'); container.id = 'container'; document.body.appendChild(container); mount( @@ -243,6 +244,12 @@ describe('', () => { expect( document.activeElement.classList.contains(`${prefix}--modal-close`) ).toEqual(true); - document.body.removeChild(container); + }); + + afterEach(() => { + if (container && container.parentNode) { + container.parentNode.removeChild(container); + } + container = null; }); }); diff --git a/packages/react/src/components/Select/Select-test.js b/packages/react/src/components/Select/Select-test.js index 10559bb5de25..2f539a12943f 100644 --- a/packages/react/src/components/Select/Select-test.js +++ b/packages/react/src/components/Select/Select-test.js @@ -150,6 +150,8 @@ describe('Select', () => { }); describe('refs', () => { + let container; + it('should accept refs', () => { class MyComponent extends React.Component { constructor(props) { @@ -164,7 +166,7 @@ describe('refs', () => { return