Skip to content
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

fix(async): add test isEverSettled after abort #985

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 25 additions & 0 deletions packages/async/src/withStatusesAtom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
AsyncStatusesFirstPending,
AsyncStatusesFulfilled,
AsyncStatusesNeverPending,
AsyncStatusesNextAbortedDuringPending,
AsyncStatusesRejected,
asyncStatusesInitState,
withStatusesAtom,
Expand Down Expand Up @@ -210,6 +211,30 @@ test('do not reject on abort', async () => {
;`👍` //?
})

test('isEverSettled after abort', async () => {
const fetchData = reatomAsync(async () => sleep()).pipe(withAbort(), withStatusesAtom())
const ctx = createTestCtx()

expect(ctx.get(fetchData.statusesAtom)).toBe(asyncStatusesInitState)
await fetchData(ctx)
expect(ctx.get(fetchData.statusesAtom).isFulfilled).toBe(true)

fetchData(ctx)
fetchData(ctx)
await null
expect(ctx.get(fetchData.statusesAtom)).toEqual({
isPending: true,
isFulfilled: false,
isRejected: false,
isSettled: false,

isFirstPending: false,
isEverPending: true,
isEverSettled: true,
} satisfies AsyncStatusesNextAbortedDuringPending)
;`👍` //?
})

test('do not reject on resource abort', async () => {
const fetchData = reatomResource(async (ctx) => {}).pipe(withStatusesAtom())
const ctx = createTestCtx()
Expand Down
10 changes: 10 additions & 0 deletions packages/async/src/withStatusesAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ export interface AsyncStatusesFirstAborted {
isEverPending: true
isEverSettled: false
}
export interface AsyncStatusesNextAbortedDuringPending {
isPending: true
isFulfilled: false
isRejected: false
isSettled: false

isFirstPending: false
isEverPending: true
isEverSettled: true
}

export interface AsyncStatusesAbortedPending {
isPending: true
Expand Down