Skip to content

Commit

Permalink
test: adjust for new document.activeElement behavior in jsdom
Browse files Browse the repository at this point in the history
  • Loading branch information
emyarod committed Feb 28, 2020
1 parent ad181ed commit 9d6a264
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
7 changes: 6 additions & 1 deletion packages/react/src/components/Checkbox/Checkbox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ describe('refs', () => {
);
}
}
const wrapper = mount(<MyComponent />);
const container = document.createElement('div');
container.id = 'container';
document.body.appendChild(container);
const wrapper = mount(<MyComponent />, {
attachTo: document.querySelector('#container'),
});
expect(document.activeElement.type).toBeUndefined();
wrapper.instance().focus();
expect(document.activeElement.type).toEqual('checkbox');
Expand Down
14 changes: 12 additions & 2 deletions packages/react/src/components/ComposedModal/ComposedModal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,25 +214,35 @@ describe('<ComposedModal />', () => {
});

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(
<ComposedModal open>
<ModalFooter primaryButtonText="Save" />
</ComposedModal>
</ComposedModal>,
{ 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(
<ComposedModal open selectorPrimaryFocus={`.${prefix}--modal-close`}>
<ModalHeader label="Optional Label" title="Example" />
<ModalFooter primaryButtonText="Save" />
</ComposedModal>
</ComposedModal>,
{ attachTo: document.querySelector('#container') }
);
expect(
document.activeElement.classList.contains(`${prefix}--modal-close`)
).toEqual(true);
document.body.removeChild(container);
});
});
7 changes: 6 additions & 1 deletion packages/react/src/components/Select/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ describe('refs', () => {
return <Select id="test" labelText="testlabel" ref={this.myRef} />;
}
}
const wrapper = mount(<MyComponent />);
const container = document.createElement('div');
container.id = 'container';
document.body.appendChild(container);
const wrapper = mount(<MyComponent />, {
attachTo: document.querySelector('#container'),
});
expect(document.activeElement.type).toBeUndefined();
wrapper.instance().focus();
expect(document.activeElement.type).toEqual('select-one');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ describe('TextInput', () => {
);
}
}
const wrapper = mount(<MyComponent />);
const container = document.createElement('div');
container.id = 'container';
document.body.appendChild(container);
const wrapper = mount(<MyComponent />, {
attachTo: document.querySelector('#container'),
});
expect(document.activeElement.type).toBeUndefined();
wrapper.instance().focus();
expect(document.activeElement.type).toEqual('text');
Expand Down
7 changes: 6 additions & 1 deletion packages/react/src/components/TextInput/TextInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ describe('TextInput', () => {
);
}
}
const wrapper = mount(<MyComponent />);
const container = document.createElement('div');
container.id = 'container';
document.body.appendChild(container);
const wrapper = mount(<MyComponent />, {
attachTo: document.querySelector('#container'),
});
expect(document.activeElement.type).toBeUndefined();
wrapper.instance().focus();
expect(document.activeElement.type).toEqual('text');
Expand Down

0 comments on commit 9d6a264

Please sign in to comment.