##// END OF EJS Templates
Movin the observable implementation to the class
Movin the observable implementation to the class

File last commit:

r133:a3fba6b6c42e default
r153:8ae7abbb3114 default
Show More
subject-tests.ts
78 lines | 1.6 KiB | video/mp2t | TypeScriptLexer
/ djx / src / test / ts / subject-tests.ts
import { observe } from "./observable";
import { subject } from "./operators/subject";
import * as tap from "tap";
tap.test("Subject tests", t => {
let nextEvent: (value: string) => void = () => void (0);
const subj1 = observe<string>(({ next }) => {
t.comment("Start subject");
nextEvent = next;
return () => {
nextEvent = () => void (0);
t.comment("Stop subject");
};
}).pipe(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<string>(({ next, complete }) => {
t.comment("Start subject");
complete();
nextEvent = next;
return () => {
nextEvent = () => void (0);
t.comment("Stop subject");
};
}).pipe(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));