mirror of
https://github.com/atom/atom.git
synced 2026-01-25 14:59:03 -05:00
Fail focus tests quickly and clearly if document isn't focused
This commit is contained in:
committed by
Antonio Scandurra
parent
3e87f9f889
commit
b9feddacbe
@@ -186,6 +186,8 @@ describe('TextEditorComponent', () => {
|
||||
|
||||
describe('focus', () => {
|
||||
it('focuses the hidden input element and adds the is-focused class when focused', async () => {
|
||||
assertDocumentFocused()
|
||||
|
||||
const {component, element, editor} = buildComponent()
|
||||
const {hiddenInput} = component.refs
|
||||
|
||||
@@ -206,6 +208,8 @@ describe('TextEditorComponent', () => {
|
||||
})
|
||||
|
||||
it('updates the component when the hidden input is focused directly', async () => {
|
||||
assertDocumentFocused()
|
||||
|
||||
const {component, element, editor} = buildComponent()
|
||||
const {hiddenInput} = component.refs
|
||||
expect(element.classList.contains('is-focused')).toBe(false)
|
||||
@@ -217,6 +221,8 @@ describe('TextEditorComponent', () => {
|
||||
})
|
||||
|
||||
it('gracefully handles a focus event that occurs prior to the attachedCallback of the element', () => {
|
||||
assertDocumentFocused()
|
||||
|
||||
const {component, element, editor} = buildComponent({attach: false})
|
||||
const parent = document.createElement('text-editor-component-test-element')
|
||||
parent.appendChild(element)
|
||||
@@ -361,3 +367,9 @@ function textNodesForScreenRow (component, row) {
|
||||
const screenLine = component.getModel().screenLineForScreenRow(row)
|
||||
return component.textNodesByScreenLineId.get(screenLine.id)
|
||||
}
|
||||
|
||||
function assertDocumentFocused () {
|
||||
if (!document.hasFocus()) {
|
||||
throw new Error('The document needs to be focused to run this test')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user