#Slow function call takes a lambda. How do I cleanly assert multiple things when it completes?

9 messages · Page 1 of 1 (latest)

hexed chasm
#
export const slowFunctionCall = async (cb: (x: X) => void): Promise<void> => {...};

In a test, I need to assert things like this:

let occurrence1Count = 0;

await slowFunctionCall((x) => {
  occurrence1Count = occurrence1Count + (x.actual === expected ? 1 : 0)
});

expect(occurrence1Count).toEqual(1);

I'm going to have occurrence1Count all the way to occurrence9Count. Is there a cleaner way to write this than 9 lets at the top?

#

thinking out loud, I suppose I can put all the x into an array of X. That might look a lot better.

plucky blade
#

you need to call the expect after the call completes

#

so you need to either await the function call

#

ot use .then

hexed chasm
#

Fixed. That was just a typo.

#

I figured this out by putting all x into an array then checking it after the await

#

This can be closed

plucky blade
#

!resolved