-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelayed-string.spec.ts
32 lines (28 loc) · 1.35 KB
/
delayed-string.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { describe, expect, test } from "@jest/globals";
import { DelayedStringFactory } from "./delayed-string";
describe("Delayed string", () => {
test("first factory should return a promise that resolves to the given string", async () => {
const factory = new DelayedStringFactory();
const promise = factory.getOrCreateStringPromise1(100, "Hello");
const result = await promise;
expect(result).toBe("Hello");
});
test("first factory should return the original promise when called again", async () => {
const factory = new DelayedStringFactory();
const promise1 = factory.getOrCreateStringPromise1(100, "Hello");
const promise2 = factory.getOrCreateStringPromise1(100, "Goodbye");
expect(promise2).toBe(promise1);
});
test("second factory should return a promise that resolves to the given string", async () => {
const factory = new DelayedStringFactory();
const promise = factory.getOrCreateStringPromise2(100, "Hello");
const result = await promise;
expect(result).toBe("Hello");
});
test("second factory should return the original promise when called again", async () => {
const factory = new DelayedStringFactory();
const promise1 = factory.getOrCreateStringPromise2(100, "Hello");
const promise2 = factory.getOrCreateStringPromise2(100, "Goodbye");
expect(promise2).toBe(promise1);
});
});