diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index e6256a0bd..2d959f0a4 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -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') + } +}