mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-12 16:52:50 +00:00
properly convert callback to a promise (#10773)
This commit is contained in:
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user