-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPromisedValue.test.ts
More file actions
32 lines (23 loc) · 987 Bytes
/
PromisedValue.test.ts
File metadata and controls
32 lines (23 loc) · 987 Bytes
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, it } from 'vitest';
import PromisedValue from './PromisedValue';
describe('PromisedValue', () => {
it('works like a promise', async () => {
const promisedString = new PromisedValue<string>();
expect(promisedString.value).toBe(null);
expect(promisedString.isResolved()).toBe(false);
promisedString.resolve('foo');
expect(promisedString.isResolved()).toBe(true);
expect(promisedString.value).toBe('foo');
const resolvedValue = await promisedString;
expect(resolvedValue).toBe('foo');
});
it('can update values', async () => {
const promisedString = new PromisedValue<string>();
promisedString.resolve('foo');
promisedString.resolve('bar');
expect(promisedString.isResolved()).toBe(true);
expect(promisedString.value).toBe('bar');
const resolvedValue = await promisedString;
expect(resolvedValue).toBe('bar');
});
});