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