properly convert callback to a promise (#10773)

This commit is contained in:
Martin Raifer
2025-02-16 11:08:08 +01:00
committed by GitHub
parent a7038955ca
commit be8dd830d8

View File

@@ -40,15 +40,21 @@ Reflect.set(
global,
'it',
Object.assign(
(msg: string, fn: (done?: () => void) => void | Promise<void>) => {
(msg: string, fn: (done?: (err?: any) => void) => void | Promise<void>) => {
_it(msg, () => {
if (fn.length) {
// there is a done callback -> return a promise instead
return new Promise<void>((done) => fn(done));
return new Promise<void>((resolve, reject) => fn(err => {
if (err) {
reject(err);
} else {
resolve();
}
}));
} else {
// no done callback -> normal behaviour
return fn();
}
// no done callback -> normal behaviour
return fn();
});
},
{ todo: _it.todo, skip: _it.skip, only: _it.only, each: _it.each },