Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,31 @@ describe('createInfiniteQueryController', () => {
}
})

it('should return the same result between reads when nothing changed', async () => {
const key = queryKey()

class Host extends LitElement {
readonly infinite = createInfiniteQueryController(
this,
{
queryKey: key,
queryFn: () => sleep(10).then(() => 'data'),
initialPageParam: 0,
getNextPageParam: () => undefined,
},
queryClient,
)
}
customElements.define(generateElementName(), Host)
const host = new Host()
container.append(host)
const infinite = host.infinite

await vi.advanceTimersByTimeAsync(10)
const result = infinite()
expect(infinite()).toBe(result)
})

it('should preserve prior pages consistently when fetching the next page fails', async () => {
const key = queryKey()

Expand Down
27 changes: 27 additions & 0 deletions packages/lit-query/src/__tests__/createQueriesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,33 @@ describe('createQueriesController', () => {
}
})

it('should return the same result between reads when nothing changed', async () => {
const key = queryKey()

class Host extends LitElement {
readonly queries = createQueriesController(
this,
{
queries: [
{
queryKey: key,
queryFn: () => sleep(10).then(() => 'data'),
},
],
},
queryClient,
)
}
customElements.define(generateElementName(), Host)
const host = new Host()
container.append(host)
const queries = host.queries

await vi.advanceTimersByTimeAsync(10)
const result = queries()
expect(queries()).toBe(result)
})

it('should support dynamic add/remove and keep partial failure stability', async () => {
const key1 = queryKey()
const key2 = queryKey()
Expand Down
23 changes: 23 additions & 0 deletions packages/lit-query/src/__tests__/createQueryController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,29 @@ describe('createQueryController', () => {
}
})

it('should return the same result between reads when nothing changed', async () => {
const key = queryKey()

class Host extends LitElement {
readonly query = createQueryController(
this,
{
queryKey: key,
queryFn: () => sleep(10).then(() => 'data'),
},
queryClient,
)
}
customElements.define(generateElementName(), Host)
const host = new Host()
container.append(host)
const query = host.query

await vi.advanceTimersByTimeAsync(10)
const result = query()
expect(query()).toBe(result)
})

it('should transition from pending to success with expected contract', async () => {
const key = queryKey()

Expand Down
Loading