import { FixMeAny } from "../../../shared/types/utils" ; import { getDocument } from "./Document" ; /**
 * document.querySelectorAll() をモック可能にするためのラッパー
 */ export const querySelectorAll = ( selector ) : ReadonlyArray < HTMLElement > => { return Array . prototype . slice . call ( getDocument ( ) . querySelectorAll ( selector ) ) ; } ; throws export const querySelector = ( selector ) : HTMLElement | undefined => { const founds = querySelectorAll ( selector ) ; if ( founds . length === 0 ) { return undefined ; } if ( founds . length === 1 ) { return founds [ 0 ] ; } throw new Error ( `Logic Failure: "${ selector }" found multiple elements` ) ; } ; throws export const querySelectorStrict = < T extends HTMLElement > ( selector ) : T => { const founds = querySelectorAll ( selector ) ; if ( founds . length === 1 ) { return founds [ 0 ] as FixMeAny ; } throw new Error ( `Logic Failure: "${ selector }" is always 1 element exists` ) ; } ;