import { describe, it } from 'node:test' import { strict as assert } from 'node:assert' import focusableSelectors from './index.js' const escapeRegExp = string => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') const re = string => new RegExp(escapeRegExp(string)) describe(' elements', () => { const selector = focusableSelectors.find( selector => selector.startsWith('a') && !selector.startsWith('area') ) it('should only include elements with [href]', () => { assert.match(selector, re('[href]')) assert.doesNotMatch(selector, re(':not([href])')) }) it('should only include not inert elements', () => { assert.match(selector, re(':not([inert])')) assert.match(selector, re(':not([inert] *)')) }) it('should only include elements without negative [tabindex]', () => { assert.match(selector, re(':not([tabindex^="-"])')) }) }) describe(' elements', () => { const selector = focusableSelectors.find(selector => selector.startsWith('area') ) it('should only include elements with [href]', () => { assert.match(selector, re('[href]')) assert.doesNotMatch(selector, re(':not([href])')) }) it('should only include not inert elements', () => { assert.match(selector, re(':not([inert])')) assert.match(selector, re(':not([inert] *)')) }) it('should only include elements without negative [tabindex]', () => { assert.match(selector, re(':not([tabindex^="-"])')) }) }) describe(' (non-radio) elements', () => { const selector = focusableSelectors.find( selector => selector.startsWith('input') && !selector.startsWith('input[type="radio"]') ) it('should only include non-radio elements', () => { assert.match(selector, re(':not([type="radio"])')) }) it('should only include non-hidden elements', () => { assert.match(selector, re(':not([type="hidden"])')) }) it('should only include not inert elements', () => { assert.match(selector, re(':not([inert])')) assert.match(selector, re(':not([inert] *)')) }) it('should only include elements without negative [tabindex]', () => { assert.match(selector, re(':not([tabindex^="-"])')) }) it('should only include elements not :disabled', () => { assert.match(selector, re(':not(:disabled)')) }) }) describe(' (radio) elements', () => { const selector = focusableSelectors.find(selector => selector.startsWith('input[type="radio"]') ) it('should only include not inert elements', () => { assert.match(selector, re(':not([inert])')) assert.match(selector, re(':not([inert] *)')) }) it('should only include elements without negative [tabindex]', () => { assert.match(selector, re(':not([tabindex^="-"])')) }) it('should only include elements not :disabled', () => { assert.match(selector, re(':not(:disabled)')) }) }) describe('