Skip to content

Commit a9163f7

Browse files
test: stabilize annotation reference autofocus
1 parent 2aca641 commit a9163f7

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

‎src/extensions/annotator/components/annotation_reference_input/__tests__/annotation_reference_input.test.tsx‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,27 @@ describe('AnnotationReferenceInput', () => {
200200
})
201201
})
202202

203-
it('restores focus after an enclosing overlay finishes closing', async () => {
204-
const { input } = renderInput()
203+
it('restores focus after an enclosing overlay finishes closing', () => {
204+
jest.useFakeTimers()
205205
const previousTrigger = document.createElement('button')
206206
document.body.appendChild(previousTrigger)
207207

208-
act(() => {
209-
previousTrigger.focus()
210-
})
211-
expect(document.activeElement).toBe(previousTrigger)
212-
213-
await waitFor(() => expect(document.activeElement).toBe(input))
214-
previousTrigger.remove()
208+
try {
209+
const { input } = renderInput()
210+
211+
act(() => {
212+
previousTrigger.focus()
213+
})
214+
expect(document.activeElement).toBe(previousTrigger)
215+
216+
act(() => {
217+
jest.advanceTimersByTime(20)
218+
})
219+
expect(document.activeElement).toBe(input)
220+
} finally {
221+
previousTrigger.remove()
222+
jest.useRealTimers()
223+
}
215224
})
216225

217226
it('supports arrow-key selection before insertion', () => {

0 commit comments

Comments
 (0)