import { render, waitFor } from '@testing-library/react' import React, { Fragment, createElement, useEffect, useState } from 'react' import { ListboxMode, ListboxState, assertActiveElement, assertActiveListboxOption, assertListbox, assertListboxButton, assertListboxButtonLinkedWithListbox, assertListboxButtonLinkedWithListboxLabel, assertListboxLabel, assertListboxOption, assertNoActiveListboxOption, getByText, getListbox, getListboxButton, getListboxButtons, getListboxLabel, getListboxOptions, getListboxes, } from '../../test-utils/accessibility-assertions' import { Keys, MouseButton, click, focus, mouseLeave, mouseMove, press, rawClick, shift, type, word, } from '../../test-utils/interactions' import { suppressConsoleLogs } from '../../test-utils/suppress-console-logs' import { Transition } from '../transition/transition' import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from './listbox' jest.mock('../../hooks/use-id') beforeAll(() => { jest.spyOn(window, 'requestAnimationFrame').mockImplementation(setImmediate as any) jest.spyOn(window, 'cancelAnimationFrame').mockImplementation(clearImmediate as any) }) afterAll(() => jest.restoreAllMocks()) describe('safeguards', () => { it.each([ ['Listbox.Button', Listbox.Button], ['Listbox.Label', Listbox.Label], ['Listbox.Options', Listbox.Options], ['Listbox.Option', Listbox.Option], ])( 'should error when we are using a <%s /> without a parent ', suppressConsoleLogs((name, Component) => { if (name === 'Listbox.Label') { // @ts-expect-error This is fine expect(() => render(createElement(Component))).toThrow( 'You used a