Skip to content

Commit c31dc7e

Browse files
authored
test: touchups and one added case (#37)
1 parent 5f5ac30 commit c31dc7e

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

spec/tests/useAsyncIterMulti.spec.ts

+26-3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,29 @@ describe('`useAsyncIterMulti` hook', () => {
163163
]);
164164
});
165165

166+
it(
167+
gray("When given multiple iterables, some empty, reflects each's states correctly"),
168+
async () => {
169+
let timesRerendered = 0;
170+
171+
const iter = asyncIterOf('a');
172+
const emptyIter = asyncIterOf();
173+
174+
const renderedHook = await act(() =>
175+
renderHook(() => {
176+
timesRerendered++;
177+
return useAsyncIterMulti([iter, emptyIter]);
178+
})
179+
);
180+
181+
expect(timesRerendered).toStrictEqual(2);
182+
expect(renderedHook.result.current).toStrictEqual([
183+
{ value: 'a', pendingFirst: false, done: true, error: undefined },
184+
{ value: undefined, pendingFirst: false, done: true, error: undefined },
185+
]);
186+
}
187+
);
188+
166189
it(
167190
gray(
168191
"When given multiple iterables with corresponding initial values, reflects each's states correctly, starting with its corresponding initial value"
@@ -204,7 +227,7 @@ describe('`useAsyncIterMulti` hook', () => {
204227

205228
it(
206229
gray(
207-
"When given multiple iterables with corresponding initial values for some, reflects each's states correctly, possibly starting with a corresponding initial value if present"
230+
"When given multiple iterables with corresponding initial values for only some, reflects each's states correctly, possibly starting with a corresponding initial value if present"
208231
),
209232
async () => {
210233
const channels = [
@@ -421,7 +444,7 @@ describe('`useAsyncIterMulti` hook', () => {
421444
}
422445
);
423446

424-
it(gray('When unmounted will close all the last held active iterators'), async () => {
447+
it(gray('When unmounted will close all active iterators it has been holding'), async () => {
425448
const channel1 = new IteratorChannelTestHelper<'a' | 'b' | 'c'>();
426449
const channel2 = new IteratorChannelTestHelper<'a' | 'b' | 'c'>();
427450

@@ -459,7 +482,7 @@ describe('`useAsyncIterMulti` hook', () => {
459482

460483
it(
461484
gray(
462-
'When adding / removing / swapping positions of iterables, their ongoing states are maintained every step regardless of position and are closed only when they disappear altogether from passed array'
485+
'When adding / removing / swapping positions of iterables, their ongoing states are maintained at every step regardless of position and get closed only when they disappear altogether from passed array'
463486
),
464487
async () => {
465488
const values: (string | IteratorChannelTestHelper<string>)[] = [];

spec/utils/asyncIterOf.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export { asyncIterOf };
22

3-
function asyncIterOf<const T>(...values: T[]) {
3+
function asyncIterOf(...values: []): AsyncIterable<never>;
4+
function asyncIterOf<const T>(...values: T[]): AsyncIterable<T>;
5+
function asyncIterOf<const T>(...values: T[]): AsyncIterable<T> {
46
return {
57
async *[Symbol.asyncIterator]() {
68
yield* values;

0 commit comments

Comments
 (0)