From ed3dea16c2ba0d3e853f3c368acfafbf850f8572 Mon Sep 17 00:00:00 2001 From: Daniel Sokolowski Date: Sun, 7 Mar 2021 20:07:08 +0100 Subject: [PATCH] Fix testing Future combine --- src/testing.ts | 2 +- test/testing.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/testing.ts b/src/testing.ts index da9f477..cfa852f 100644 --- a/src/testing.ts +++ b/src/testing.ts @@ -74,7 +74,7 @@ export function doesOccur( CombineFuture.prototype.model = function() { const a = this.parentA.model(); const b = this.parentB.model(); - return a.time <= b.time ? a : b; + return doesOccur(a) && (!doesOccur(b) || a.time <= b.time) ? a : b; }; MapFuture.prototype.model = function() { diff --git a/test/testing.ts b/test/testing.ts index e72f7aa..231be53 100644 --- a/test/testing.ts +++ b/test/testing.ts @@ -1,6 +1,6 @@ import { assert } from "chai"; import * as H from "../src"; -import { Behavior, Stream, Now } from "../src"; +import { Behavior, Stream, never, Now } from "../src"; import { testFuture, assertFutureEqual, @@ -44,6 +44,20 @@ describe("testing", () => { const res = H.combine(fut1, fut2); assertFutureEqual(res, fut2); }); + it("gives first future if only resolved", () => { + const fut1 = testFuture(4, "foo"); + const res = H.combine(fut1, never); + assertFutureEqual(res, fut1); + }); + it("gives second future if only resolved", () => { + const fut2 = testFuture(3, "bar"); + const res = H.combine(never, fut2); + assertFutureEqual(res, fut2); + }); + it("gives never if none resolved", () => { + const res = H.combine(never, never); + assertFutureEqual(res, never); + }); }); describe("functor", () => { it("maps value", () => {