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.

Helpers: Suspense (and others?)

See original GitHub issue

#105 had some great discussion around helpers - the example raised there was for components with async setup functions (used in <Suspense>). Testing those alone won’t work, since if you have a async setup, Vue expected a <Suspense> wrapper.

We could provide a helper (this works)

  test('uses a helper to mount a component with async setup', async () => {
    const Comp = defineComponent({
      async setup() {
        return () => h('div', 'Async Setup')
      }
    })

    const mountSuspense = async (component: new () => ComponentPublicInstance, options) => {
      const wrapper = mount(defineComponent({
        render() {
          return h(Suspense, null, {
            default: h(component),
            fallback: h('div', 'fallback')
          })
        }
      })
      ...options)
      await flushPromises()
      return wrapper
    }

    const wrapper = mountSuspense(Comp)
    console.log(wrapper.html()) //=> <div>Async Setup</div>
  })

Some thoughts:

  • we call flushPromises for the user. Any possible side-effects/unexpected behavior?
  • does this belong in this library? Or should we mention in the docs and let users write their own?
  • this sets a precedent. One we have one helper, it may be expected others are included. This is not a bad thing, just something to keep in mind.
  • do we also then need a shallowMountSuspense? Someone will almost certainly ask for this.
    • if we drop shallowMount as a stand-alone function (which I think we should) and instead have a shallow: true mounting option, this would not be a problem.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:32 (25 by maintainers)

github_iconTop GitHub Comments

1reaction
afontcucommented, Oct 1, 2020

Hey @lmiller1990 the renderStubDefaultSlot option is a great idea and would help me out a lot! When do you think it might make it into a release?

it’s already there 😃 https://github.com/vuejs/vue-test-utils-next/pull/102

1reaction
lmiller1990commented, Jul 19, 2020

Yes, I agree, we should add this as a global config too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Helpers: Suspense (and others?) · Issue #108 · vuejs/test-utils
The main one I'm thinking about is a Suspense helper. Happy to let this sit and add things as people ask for them....
Read more >
ETHEL BARRYMORE & GENE KELLY star in "To Find Help ...
So popular, in fact, it was done three times (like several stories) Last year I uploaded a version with "The First Lady of...
Read more >
The Psychology of Suspense - CrimeReads
Suspense is an uncomfortable pleasure. Effective mysteries and thrillers keep readers grinning and squirming at the same time.
Read more >
Concurrent UI Patterns (Experimental) - React
The “posts” and “fun facts” responses come within 100ms of each other. But React coalesces them and “reveals” their Suspense boundaries together.
Read more >
Elements Of Suspense: The Complete Guide To Being Utterly ...
Learn how to be utterly suspenseful with our complete guide to the elements of suspense, filled with examples and practical tips.
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