mounted.ts 588 B

12345678910111213141516171819202122232425
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import renderComponent, {
  3. type ExtendedRenderResult,
  4. } from './renderComponent.ts'
  5. const components = new Set<ExtendedRenderResult>()
  6. afterEach(() => {
  7. components.forEach((component) => {
  8. component.unmount()
  9. })
  10. })
  11. export const mounted = <T>(fn: () => T) => {
  12. let result: T
  13. const component = renderComponent({
  14. template: '<div></div>',
  15. setup() {
  16. result = fn()
  17. },
  18. })
  19. components.add(component)
  20. // @ts-expect-error doesn't know that setup is called in sync
  21. return result
  22. }