Vue-test-utils: Async API like "waitForElementVisible(selector, [timeout])"

Created on 14 Nov 2017  路  4Comments  路  Source: vuejs/vue-test-utils

feature request

All 4 comments

I dont find how can I do this check for now

I don't think we should add this to vue-test-utils. Waiting for promises/ timeouts to resolve isn't a vue specific problem. I'm happy to discuss this though because a few people have requested a similar feature.

You can wait for promises to resolve using flush-promises.

import flushPromises from 'flush-promises'

test('an async component', async () => {
  const wrapper = mount(AsyncComponent)
  await flushPromises()
  expect(wrapper.contains('div')).toBe(true)
})

@eddyerburgh Thanks for explaining and I see your points.

I'm using setTimeout/_.defer to work around which seems exactly what flush-promises does.

I second this shouldn't be in vue-test-utils. This is a common request - but I think people really asking "how do I do this" rather than "make the feature".

I think the best solution is a guide in the docs how on to deal with async.

Edit: see #151 .

Was this page helpful?
0 / 5 - 0 ratings