import { observe, subject } from "./observable"; import * as tap from "tap"; tap.test("Subject tests", t => { let nextEvent: (value: string) => void = () => void (0); const subj1 = observe(subject(({ next }) => { t.comment("Start subject"); nextEvent = next; return () => { nextEvent = () => void (0); t.comment("Stop subject"); }; })); const h1 = subj1.subscribe({ next: v => t.comment(`h1 next: ${v}`) }); nextEvent("first"); const h2 = subj1.subscribe({ next: v => t.comment(`h2 next: ${v}`) }); nextEvent("second"); h1.unsubscribe(); nextEvent("third"); h2.unsubscribe(); t.pass("Subject finished"); t.end(); }).catch(e => console.error(e)); tap.test("Subject tests #2", t => { let nextEvent: (value: string) => void = () => void (0); const subj1 = observe(subject(({ next, complete }) => { t.comment("Start subject"); complete(); nextEvent = next; return () => { nextEvent = () => void (0); t.comment("Stop subject"); }; })); const h1 = subj1.subscribe({ next: v => t.comment(`h1 next: ${v}`) }); nextEvent("first"); const h2 = subj1.subscribe({ next: v => t.comment(`h2 next: ${v}`) }); nextEvent("second"); h1.unsubscribe(); nextEvent("third"); h2.unsubscribe(); t.pass("Subject finished"); t.end(); }).catch(e => console.error(e));