toHaveCurrentUrl.ts 852 B

1234567891011121314151617181920212223242526272829
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { ExtendedRenderResult } from '../components/renderComponent.ts'
  3. // eslint-disable-next-line sonarjs/cognitive-complexity
  4. export default function toHaveCurrentUrl(
  5. this: any,
  6. view: ExtendedRenderResult,
  7. url: string,
  8. ) {
  9. if (typeof url !== 'string') {
  10. throw new Error(`"toHaveCurrentUrl" expects a string, got ${typeof url}`)
  11. }
  12. if (!view.router) {
  13. throw new Error(
  14. `The value passed to "expect" is not a result of "visitView" method because it doesn't provide a "router" property.`,
  15. )
  16. }
  17. const pass = view.router.currentRoute.value.path === url
  18. return {
  19. pass,
  20. message: () =>
  21. `expected current route${
  22. this.isNot ? ' not' : ''
  23. } to be ${url}, but got ${view.router.currentRoute.value.path}`,
  24. }
  25. }