diff --git a/packages/react/src/components/Checkbox/Checkbox-test.js b/packages/react/src/components/Checkbox/Checkbox-test.js
index f1d257704396..a432799a0f6e 100644
--- a/packages/react/src/components/Checkbox/Checkbox-test.js
+++ b/packages/react/src/components/Checkbox/Checkbox-test.js
@@ -131,7 +131,12 @@ describe('refs', () => {
);
}
}
- const wrapper = mount();
+ const container = document.createElement('div');
+ container.id = 'container';
+ document.body.appendChild(container);
+ const wrapper = mount(, {
+ attachTo: document.querySelector('#container'),
+ });
expect(document.activeElement.type).toBeUndefined();
wrapper.instance().focus();
expect(document.activeElement.type).toEqual('checkbox');
diff --git a/packages/react/src/components/ComposedModal/ComposedModal-test.js b/packages/react/src/components/ComposedModal/ComposedModal-test.js
index 4a2f5eae1c76..e29dca8174c1 100644
--- a/packages/react/src/components/ComposedModal/ComposedModal-test.js
+++ b/packages/react/src/components/ComposedModal/ComposedModal-test.js
@@ -214,25 +214,35 @@ describe('', () => {
});
it('should focus on the primary actionable button in ModalFooter by default', () => {
+ const container = document.createElement('div');
+ container.id = 'container';
+ document.body.appendChild(container);
mount(
-
+ ,
+ { attachTo: document.querySelector('#container') }
);
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.id = 'container';
+ document.body.appendChild(container);
mount(
-
+ ,
+ { attachTo: document.querySelector('#container') }
);
expect(
document.activeElement.classList.contains(`${prefix}--modal-close`)
).toEqual(true);
+ document.body.removeChild(container);
});
});
diff --git a/packages/react/src/components/Select/Select-test.js b/packages/react/src/components/Select/Select-test.js
index 88e8098c0eda..10559bb5de25 100644
--- a/packages/react/src/components/Select/Select-test.js
+++ b/packages/react/src/components/Select/Select-test.js
@@ -164,7 +164,12 @@ describe('refs', () => {
return ;
}
}
- const wrapper = mount();
+ const container = document.createElement('div');
+ container.id = 'container';
+ document.body.appendChild(container);
+ const wrapper = mount(, {
+ attachTo: document.querySelector('#container'),
+ });
expect(document.activeElement.type).toBeUndefined();
wrapper.instance().focus();
expect(document.activeElement.type).toEqual('select-one');
diff --git a/packages/react/src/components/TextInput/ControlledPasswordInput-test.js b/packages/react/src/components/TextInput/ControlledPasswordInput-test.js
index f3552f8cf046..7093643ef111 100644
--- a/packages/react/src/components/TextInput/ControlledPasswordInput-test.js
+++ b/packages/react/src/components/TextInput/ControlledPasswordInput-test.js
@@ -47,7 +47,12 @@ describe('TextInput', () => {
);
}
}
- const wrapper = mount();
+ const container = document.createElement('div');
+ container.id = 'container';
+ document.body.appendChild(container);
+ const wrapper = mount(, {
+ attachTo: document.querySelector('#container'),
+ });
expect(document.activeElement.type).toBeUndefined();
wrapper.instance().focus();
expect(document.activeElement.type).toEqual('text');
diff --git a/packages/react/src/components/TextInput/TextInput-test.js b/packages/react/src/components/TextInput/TextInput-test.js
index 0cb0f2b8485a..7ff1cd0737df 100644
--- a/packages/react/src/components/TextInput/TextInput-test.js
+++ b/packages/react/src/components/TextInput/TextInput-test.js
@@ -47,7 +47,12 @@ describe('TextInput', () => {
);
}
}
- const wrapper = mount();
+ const container = document.createElement('div');
+ container.id = 'container';
+ document.body.appendChild(container);
+ const wrapper = mount(, {
+ attachTo: document.querySelector('#container'),
+ });
expect(document.activeElement.type).toBeUndefined();
wrapper.instance().focus();
expect(document.activeElement.type).toEqual('text');