mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-05 23:38:30 +08:00
18 lines
543 B
TypeScript
18 lines
543 B
TypeScript
import { sequential } from "./sequential";
|
|
|
|
test("sequential functions should run sequentially", () => {
|
|
let time = 10;
|
|
const f = sequential(() => new Promise(resolve => setTimeout(resolve, time--)));
|
|
|
|
const resolved_values: number[] = [];
|
|
let last_promise!: Promise<any>;
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
last_promise = f().then(() => resolved_values.push(i));
|
|
}
|
|
|
|
expect(resolved_values).toEqual([]);
|
|
|
|
return last_promise.then(() => expect(resolved_values).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]));
|
|
});
|