Skip to content

Commit

Permalink
test: clean up container div
Browse files Browse the repository at this point in the history
  • Loading branch information
emyarod committed Feb 28, 2020
1 parent 9d6a264 commit abaa7aa
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
11 changes: 10 additions & 1 deletion packages/react/src/components/Checkbox/Checkbox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ describe('Checkbox', () => {
});

describe('refs', () => {
let container;

it('should accept refs', () => {
class MyComponent extends React.Component {
constructor(props) {
Expand All @@ -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(<MyComponent />, {
Expand Down Expand Up @@ -162,6 +164,13 @@ describe('refs', () => {
const wrapper = mount(<MyComponent />);
expect(wrapper.find('input').getDOMNode().indeterminate).toBe(true);
});

afterEach(() => {
if (container && container.parentNode) {
container.parentNode.removeChild(container);
}
container = null;
});
});

describe('CheckboxSkeleton', () => {
Expand Down
15 changes: 11 additions & 4 deletions packages/react/src/components/ComposedModal/ComposedModal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ describe('<ModalFooter />', () => {
});

describe('<ComposedModal />', () => {
let container;

it('renders', () => {
const wrapper = mount(<ComposedModal open />);
expect(wrapper).toMatchSnapshot();
Expand Down Expand Up @@ -214,7 +216,7 @@ describe('<ComposedModal />', () => {
});

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(
Expand All @@ -226,11 +228,10 @@ describe('<ComposedModal />', () => {
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(
Expand All @@ -243,6 +244,12 @@ describe('<ComposedModal />', () => {
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;
});
});
11 changes: 10 additions & 1 deletion packages/react/src/components/Select/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ describe('Select', () => {
});

describe('refs', () => {
let container;

it('should accept refs', () => {
class MyComponent extends React.Component {
constructor(props) {
Expand All @@ -164,7 +166,7 @@ describe('refs', () => {
return <Select id="test" labelText="testlabel" ref={this.myRef} />;
}
}
const container = document.createElement('div');
container = document.createElement('div');
container.id = 'container';
document.body.appendChild(container);
const wrapper = mount(<MyComponent />, {
Expand All @@ -174,6 +176,13 @@ describe('refs', () => {
wrapper.instance().focus();
expect(document.activeElement.type).toEqual('select-one');
});

afterEach(() => {
if (container && container.parentNode) {
container.parentNode.removeChild(container);
}
container = null;
});
});

describe('SelectSkeleton', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('TextInput', () => {
const textInput = () => wrapper.find('input');

describe('input', () => {
let container;

it('renders as expected', () => {
expect(textInput().length).toBe(1);
});
Expand All @@ -47,7 +49,7 @@ describe('TextInput', () => {
);
}
}
const container = document.createElement('div');
container = document.createElement('div');
container.id = 'container';
document.body.appendChild(container);
const wrapper = mount(<MyComponent />, {
Expand Down Expand Up @@ -96,6 +98,13 @@ describe('TextInput', () => {
wrapper.setProps({ placeholder: 'Enter text' });
expect(textInput().props().placeholder).toEqual('Enter text');
});

afterEach(() => {
if (container && container.parentNode) {
container.parentNode.removeChild(container);
}
container = null;
});
});

describe('label', () => {
Expand Down
11 changes: 10 additions & 1 deletion packages/react/src/components/TextInput/TextInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('TextInput', () => {
const textInput = () => wrapper.find('input');

describe('input', () => {
let container;

it('renders as expected', () => {
expect(textInput().length).toBe(1);
});
Expand All @@ -47,7 +49,7 @@ describe('TextInput', () => {
);
}
}
const container = document.createElement('div');
container = document.createElement('div');
container.id = 'container';
document.body.appendChild(container);
const wrapper = mount(<MyComponent />, {
Expand Down Expand Up @@ -96,6 +98,13 @@ describe('TextInput', () => {
wrapper.setProps({ placeholder: 'Enter text' });
expect(textInput().props().placeholder).toEqual('Enter text');
});

afterEach(() => {
if (container && container.parentNode) {
container.parentNode.removeChild(container);
}
container = null;
});
});

describe('label', () => {
Expand Down

0 comments on commit abaa7aa

Please sign in to comment.