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 ashallow: true
mounting option, this would not be a problem.
- if we drop
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:32 (25 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
it’s already there 😃 https://github.com/vuejs/vue-test-utils-next/pull/102
Yes, I agree, we should add this as a global config too.