diff --git a/src/Future.ts b/src/Future.ts index 3b4af3c..1c61386 100644 --- a/src/Future.ts +++ b/src/Future.ts @@ -269,7 +269,7 @@ export class Future { * This method is eager, will trigger the underlying Promise. */ mapFailure(fn: (x:any)=>any): Future { - const lazy = Lazy.of(()=>this.promise.get().catch(x => {throw [fn(x)]})); + const lazy = Lazy.of(()=>this.promise.get().catch(x => {throw fn(x)})); lazy.get(); return new Future(lazy); } diff --git a/tests/Future.ts b/tests/Future.ts index 6a2d50a..60a8dcf 100644 --- a/tests/Future.ts +++ b/tests/Future.ts @@ -9,7 +9,7 @@ async function ensureFailedWithValue(val: any, promise:Promise) { v = await promise; assert.ok(false); } catch (err) { - assert.equal(val, err); + assert.deepEqual(val, err); } } @@ -96,7 +96,7 @@ describe("Future.map*", () => { }); it("mapFailure works", async () => { return ensureFailedWithValue( - "oops, sorry", Future.failed("sorry").mapFailure(err => "oops, " + err).toPromise()); + "SORRY", Future.failed("sorry").mapFailure(err => err.toUpperCase()).toPromise()); }); it("mapFailure is a nop on successful futures", async () => { assert.deepEqual(5, await Future.ok(5).mapFailure(_ => "oops"));