From c3369fd0de3f7e13f4d963d8a10a263d555a37c9 Mon Sep 17 00:00:00 2001 From: emyarod Date: Wed, 26 Feb 2020 23:10:09 -0600 Subject: [PATCH] test: adjust for new document.activeElement behavior in jsdom --- .../react/src/components/Checkbox/Checkbox-test.js | 7 ++++++- .../components/ComposedModal/ComposedModal-test.js | 14 ++++++++++++-- .../react/src/components/Select/Select-test.js | 7 ++++++- .../TextInput/ControlledPasswordInput-test.js | 7 ++++++- .../src/components/TextInput/TextInput-test.js | 7 ++++++- 5 files changed, 36 insertions(+), 6 deletions(-) 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