Skip to content

Testing Suspense Component #1904

Answered by cexbrayat
jthn asked this question in Q&A
Dec 8, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @jthn

As you're waiting for 100ms in the promise, your test can't succeed
One easy way to workaround timers is to use vi.useFakeTimers().

Something like:

const mountSuspense = async (component, options) => {
  // use fake timers
  vi.useFakeTimers();
  const c = defineComponent({
    render() {
      return h(Suspense, null, {
        default: h(component),
        fallback: h("div", "fallback"),
      })
    },
  })

  const wrapper = mount(c, options)
  // advance 100ms
  vi.advanceTimersByTime(100)
  await flushPromises()

  return wrapper
}

and I think the test should succeed

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jthn
Comment options

Answer selected by jthn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants