ember-test-helpers icon indicating copy to clipboard operation
ember-test-helpers copied to clipboard

Add support for waitUntil accepting an async function?

Open makepanic opened this issue 6 years ago • 6 comments
trafficstars

Hi, I wanted to use waitUntil and pass an async function as the callback. It looks like this isn't currently supported. Is this something you would be interested in supporting?

If so I can try to open a PR which implements Promise support in waitUntil.

makepanic avatar Feb 28 '19 08:02 makepanic

@makepanic I'm not sure what would be the point of accepting an async function. If you have a function that returns a promise you can just do await myFunction(), no need for waitUntil

cibernox avatar Feb 28 '19 16:02 cibernox

I primarily needed the repeated truthy checks of waitUntil.

await waitUntil(async () => 
  await someAsyncTruthynessCheck());

where someAsyncTruthynessCheck is an async function that return true after a while/couple executions.

makepanic avatar Feb 28 '19 19:02 makepanic

Definitely would be great to be able to:

await waitUntil(async () => {
  await findAll('.class-element').length === 2;
});

Any updates on this?

tpetrone avatar Aug 05 '19 23:08 tpetrone

Hmm, @tpetrone that doesn't seem quite right. findAll does not return a promise (see API docs here), that use case should already be handled without changes to support async functions.

rwjblue avatar Aug 05 '19 23:08 rwjblue

Thanks for clarifying @rwjblue. I did had misunderstood findAll's response. In this case I don't have a particular use case for async callback support inside waitUntil.

tpetrone avatar Aug 06 '19 14:08 tpetrone

FWIW, I'm not opposed to adding support for waitUntil to handle async functions. If someone wants to pick that up, we can try to work out the details in a PR...

rwjblue avatar Aug 06 '19 14:08 rwjblue