##// END OF EJS Templates
Added tag v1.8.1 for changeset c7d9ad82b374
Added tag v1.8.1 for changeset c7d9ad82b374

File last commit:

r125:cede47727a1b v1.7.0 default
r132:b92de241dece default
Show More
subject-tests.ts
77 lines | 1.5 KiB | video/mp2t | TypeScriptLexer
/ djx / src / test / ts / subject-tests.ts
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<string>(({ 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<string>(({ 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));