I got a component with 1 child component. something like this:
<custom-component (customEvent)="foo()"></custom-component>
foo is a function that does stuff, assume is a simple increment.
I want to write a unit test that ensures that after the custom event is emitted, the increment actually happened.
what I tried to do currently in the test is something like this:
let oldValue = component.variableThatShouldBeIncremented;
childComponent.onCustomEvent.emit();
expect(component.variableThatShouldBeIncremented).toBeGreaterThan(oldValue);
this doesn't currently work. but if I wrap the expect in a setTimeout it does. this makes sense as the event is async.
I want to get rid of the setTimeout. is there a way to tell "wait until the event callback has been fulfilled"?
I've tried to look for examples but I've only found tests that are checking that a specific event has been emitted rather than checking the consequence of emitting a specific event.
EDIT:
I'm taking the yurzui answer for correct. the code should work. I've made a mistake by simplify the code for the Q, omitting the code that was actually causing the problem: the foo function.
that function was calling a function from a service and it wasn't a simple increment.
for reference purposes, my actual problem was that the spy created for the mocked version of the service didn't register the call to the function inside the event handler. the problem is now solved
(customEvent)="foo"instead of(customEvent)="foo()"?