Fixing a race condition in event listener unit test