Skip to content

Test touchups and one added case #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions spec/tests/useAsyncIterMulti.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,29 @@ describe('`useAsyncIterMulti` hook', () => {
]);
});

it(
gray("When given multiple iterables, some empty, reflects each's states correctly"),
async () => {
let timesRerendered = 0;

const iter = asyncIterOf('a');
const emptyIter = asyncIterOf();

const renderedHook = await act(() =>
renderHook(() => {
timesRerendered++;
return useAsyncIterMulti([iter, emptyIter]);
})
);

expect(timesRerendered).toStrictEqual(2);
expect(renderedHook.result.current).toStrictEqual([
{ value: 'a', pendingFirst: false, done: true, error: undefined },
{ value: undefined, pendingFirst: false, done: true, error: undefined },
]);
}
);

it(
gray(
"When given multiple iterables with corresponding initial values, reflects each's states correctly, starting with its corresponding initial value"
Expand Down Expand Up @@ -204,7 +227,7 @@ describe('`useAsyncIterMulti` hook', () => {

it(
gray(
"When given multiple iterables with corresponding initial values for some, reflects each's states correctly, possibly starting with a corresponding initial value if present"
"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"
),
async () => {
const channels = [
Expand Down Expand Up @@ -421,7 +444,7 @@ describe('`useAsyncIterMulti` hook', () => {
}
);

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

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

it(
gray(
'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'
'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'
),
async () => {
const values: (string | IteratorChannelTestHelper<string>)[] = [];
Expand Down
4 changes: 3 additions & 1 deletion spec/utils/asyncIterOf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export { asyncIterOf };

function asyncIterOf<const T>(...values: T[]) {
function asyncIterOf(...values: []): AsyncIterable<never>;
function asyncIterOf<const T>(...values: T[]): AsyncIterable<T>;
function asyncIterOf<const T>(...values: T[]): AsyncIterable<T> {
return {
async *[Symbol.asyncIterator]() {
yield* values;
Expand Down
Loading