Handle errors in Predicate function
This commit is contained in:
@@ -491,6 +491,23 @@ const testEventEmitterDebouncedOnceListener = async (): Promise<void> => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests that the `waitFor` method rejects if the predicate function throws
|
||||
*/
|
||||
const testEventEmitterWaitForRejectsOnPredicateError = async (): Promise<void> => {
|
||||
const emitter = new EventEmitter<TestEvents>();
|
||||
const listener = vi.fn();
|
||||
|
||||
const waitPromise = emitter.waitFor('message', () => {
|
||||
throw new Error('predicate error');
|
||||
});
|
||||
|
||||
emitter.emit('message', 'hello');
|
||||
|
||||
await expect(waitPromise).rejects.toThrow('predicate error');
|
||||
expect(listener).not.toHaveBeenCalled();
|
||||
};
|
||||
|
||||
const runTests = async (): Promise<void> => {
|
||||
test('EventEmitter: calls listeners when an event is emitted', testEventEmitterCallsListeners);
|
||||
test('EventEmitter: calls multiple listeners for the same event', testEventEmitterCallsMultipleListeners);
|
||||
@@ -516,6 +533,7 @@ const runTests = async (): Promise<void> => {
|
||||
test('EventEmitter: resets the debounce timer on repeated emits', testEventEmitterDebouncedTimerResetsOnRepeatedEmits);
|
||||
test('EventEmitter: does not debounce when debounceMilliseconds is zero', testEventEmitterZeroDebounceDoesNotDebounce);
|
||||
test('EventEmitter: debounces once listeners and invokes them only once', testEventEmitterDebouncedOnceListener);
|
||||
test('EventEmitter: rejects waitFor when the predicate function throws', testEventEmitterWaitForRejectsOnPredicateError);
|
||||
};
|
||||
|
||||
await runTests();
|
||||
|
||||
Reference in New Issue
Block a user