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 3: Async component with suspense wrapper

See original GitHub issue

Struggling to test a async component. I created a suspense wrapper component with defineComponent which i think should work but it doesn’t:

it("renders a async component with a suspense wrapper", () => {
  const Component = defineComponent({
    async setup() {
      return () => h("div", "AsyncSetup");
    },
  });

  const { getByText } = render(
    defineComponent({
      render() {
        return h(Suspense, null, {
          default: h(Component),
          fallback: h("div", "fallback"),
        });
      },
    })
  );

  expect(getByText("AsyncSetup")).toBeInTheDocument(); // fails
});

Also created a repository for reproducing the issue.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
Raguracommented, Sep 18, 2022

Any updates on this? We have embraced Suspense and async components very heavily in our project and this is really holding us back in writing tests. I’ve noticed it’s the last part of making this library fully Vue 3 compatible.

1reaction
sand4rtcommented, Dec 14, 2022

As workaround i’m using a modified version of the render function called renderAsync for now. The code can be viewed here.

After many problems with JSDOM/HappyDOM and issues like this i decided not to use VTL anymore. Playwright component testing has a almost identical API, is fast as well and runs in a real browser…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Suspense | Vue.js
<Suspense> is a built-in component for orchestrating async dependencies in a component tree. It can render a loading state while waiting for multiple...
Read more >
The Complete Guide to Suspense in Vue3 - CODE Magazine
The wrapped component makes use of the async setup() function and awaits an async/promise operation to fetch data from a back-end server. The ......
Read more >
Vue Suspense — Everything You Need to Know
Suspense is a built-in Vue.js 3 component, that simplifies coordinating loading states even, in deeply nested components.
Read more >
Improve User Experience in Vue 3 with Suspense
"Suspense" is a new built-in component in Vue that we can wrap around another component needing to perform an asynchronous action before it ......
Read more >
Async with Suspense - Vue Mastery
With Vue 3, we received a new and quite special component called <Suspense /> . In a nutshell, it allows us to better...
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