linkQueries.ts 600 B

12345678910111213141516171819202122232425
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { getElementError } from '@testing-library/vue'
  3. export const getLinkFromElement = (
  4. container: HTMLElement,
  5. element: Element,
  6. ): HTMLAnchorElement => {
  7. const link = element.closest('a') as HTMLAnchorElement | null
  8. if (!link) {
  9. throw getElementError(
  10. 'Recieved element is not wrapped inside a link',
  11. container,
  12. )
  13. }
  14. return link
  15. }
  16. export default function buildLinksQueries(container: HTMLElement) {
  17. return {
  18. getLinkFromElement: getLinkFromElement.bind(null, container),
  19. }
  20. }