##// END OF EJS Templates
Added childContainer service to container services, ServiceContaier is destroyable, fixed browser Uuid version
Added childContainer service to container services, ServiceContaier is destroyable, fixed browser Uuid version

File last commit:

r115:691199f665e0 ioc ts support
r146:f3f5c56d3b3e v1.4.0-rc5 default
Show More
ObservableTests.ts
74 lines | 2.0 KiB | video/mp2t | TypeScriptLexer
/ src / test / ts / tests / ObservableTests.ts
cin
migrating tests to the new project structure
r89 import { TraceSource } from "../log/TraceSource";
import { Observable } from "../Observable";
import { IObservable } from "../interfaces";
cin
corrected code to support ts strict mode...
r115 import { delay, fork } from "../safe";
cin
migrating tests to the new project structure
r89 import { test } from "./TestTraits";
const trace = TraceSource.get("ObservableTests");
test("events sequence example", async t => {
cin
corrected code to support ts strict mode...
r115 let events: IObservable<number> | undefined;
cin
migrating tests to the new project structure
r89
const done = new Promise<void>(resolve => {
events = new Observable<number>(async (notify, fail, finish) => {
for (let i = 0; i < 10; i++) {
cin
corrected code to support ts strict mode...
r115 await fork();
cin
migrating tests to the new project structure
r89 notify(i);
}
finish();
resolve();
});
});
let count = 0;
let complete = false;
cin
corrected code to support ts strict mode...
r115 if (!events)
throw new Error("events === undefined");
events.on(x => count = count + x, undefined, () => complete = true);
cin
migrating tests to the new project structure
r89
const first = await events.next();
t.equals(first, 0, "the first event");
t.false(complete, "the sequence is not complete");
await done;
t.equals(count, 45, "the summ of the evetns");
t.true(complete, "the sequence is complete");
});
test("event sequence termination", async t => {
cin
corrected code to support ts strict mode...
r115 let events: IObservable<number> | undefined;
cin
migrating tests to the new project structure
r89
const done = new Promise<void>(resolve => {
events = new Observable<number>(async (notify, fail, complete) => {
cin
corrected code to support ts strict mode...
r115 await fork();
cin
migrating tests to the new project structure
r89 notify(1);
complete();
notify(2);
complete();
fail("Sequence terminated");
resolve();
});
});
cin
corrected code to support ts strict mode...
r115 if (!events)
throw new Error("events === undefined");
cin
migrating tests to the new project structure
r89 let count = 0;
events.on(() => {}, e => count++, () => count++);
const first = await events.next();
t.equals(first, 1, "the first message");
try {
await events.next();
t.fail("shoud throw an exception");
} catch (e) {
t.pass("the sequence is terminated");
}
await done;
t.equals(count, 1, "the sequence must be terminated once");
});