question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue Test Utils' teleport stub and headlessui's Dialog don't work well together

See original GitHub issue

What package within Headless UI are you using?

@headlessui/vue

What version of that package are you using?

^1.4.2

What browser are you using?

N/A

Reproduction URL

https://github.com/dospunk/headlessui-vue-dialog-testing-error

Describe your issue

HeadlessUI’s Dialog is difficult to test because if its use of teleport. Recently Vue Test Utils added the ability to stub out teleport automatically, so that the contents of the teleport can be tested more easily. Unfortunately, this causes some sort of recursive warning with the Dialog’s FocusTrap.

In the included repo there is a test file tests/components/HelloWorld.test.js containing two tests. The first doesn’t stub teleport, and as a result fails because it cannot get the contents of the Dialog. The second does stub teleport, and so it generates a ton of warnings about FocusTrap not having any focusable elements (even though the Dialog contains a button), and then warnings about a recursive error. Ultimately the second test passes, but with a larger component it would simply time out.

You can see that no errors occur when the page actually renders in the browser by running npm run dev and navigating to the url displayed.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

2reactions
senariacommented, Jun 13, 2022

@dospunk thanks man. I am appreciating it. Apparently they moved a bit and overlay is now deprecated and if you want to use the panel you would also stub it. But definitely leaded me into the right direction. 👍

1reaction
RobinMalfaitcommented, Aug 30, 2022

Hey! Thank you for your bug report! Much appreciated! 🙏

Looks like you found a way around the problem and seems that your issue is fixed now.

HeadlessUI’s Dialog is difficult to test because if its use of teleport.

That’s sadly a reality that exists and we don’t have any plans to remove the teleport functionality from the Dialog.

The second does stub teleport, and so it generates a ton of warnings about FocusTrap not having any focusable elements (even though the Dialog contains a button), and then warnings about a recursive error.

The good news here is that in the latest version you won’t get spammend with a wall of warnings. Sadly the last warning (maximum call stack) still exists when you stub this teleport functionality. The confusing part is that this does not happen at all in production so I wonder if there is anything we can do about that in Headless UI itself. I’m also not sure what the built-in teleport stubbing is doing exactly which could result in incorrect behaviour.

Because you’ve found a workaround with manual stubs that solve your issue, I’m going to close this issue. If you or anyone else run into other issues then feel free to open a new issue with a reproduction repo attached. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Teleport
If you want to test the rest of your component, ignoring teleport, you can stub teleport by passing teleport: true in the global...
Read more >
Opening Modal Dialog in the test (vue-test-utils + jest- ...
I have a test that simulates the opening of a Modal (HeadlessUI), however, when performing the simulation of clicking the open button, ...
Read more >
Testing Teleport : r/vuejs
The trick is getComponent queries the virtual DOM, so even though the modal is rendered outside the component mounted using Vue Test Utils, ......
Read more >
how to install express in console Code Example
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution). ... E: The repository 'http://ppa.launchpad.net/certbot/certbot/ ...
Read more >
headlessui
headlessui repo issues. ... [DOCS]: https://headlessui.dev/react/tabs ... Vue Test Utils' teleport stub and headlessui's Dialog don't work well together.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found