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
@@ -1,5 +1,5 @@
import { assertType, describe, expectTypeOf, it } from 'vitest'
import { queryKey } from '@tanstack/query-test-utils'
import { createKey } from '@tanstack/query-test-utils'
import { QueryClient, dataTagSymbol, skipToken } from '@tanstack/query-core'
import { infiniteQueryOptions } from '../infinite-query-options'
import { injectInfiniteQuery } from '../inject-infinite-query'
Expand All @@ -21,7 +21,7 @@ export const exportedInfiniteQueryOptions = infiniteQueryOptions({

describe('infiniteQueryOptions', () => {
it('should not allow excess properties', () => {
const key = queryKey()
const key = createKey()
assertType(
infiniteQueryOptions({
queryKey: key,
Expand All @@ -35,7 +35,7 @@ describe('infiniteQueryOptions', () => {
})

it('should infer types for callbacks', () => {
const key = queryKey()
const key = createKey()
infiniteQueryOptions({
queryKey: key,
queryFn: () => Promise.resolve('data'),
Expand All @@ -49,7 +49,7 @@ describe('infiniteQueryOptions', () => {
})

it('should work when passed to useInfiniteQuery', () => {
const key = queryKey()
const key = createKey()
const options = infiniteQueryOptions({
queryKey: key,
queryFn: () => Promise.resolve('string'),
Expand All @@ -66,7 +66,7 @@ describe('infiniteQueryOptions', () => {
})

it('should work when passed to fetchInfiniteQuery', async () => {
const key = queryKey()
const key = createKey()
const options = infiniteQueryOptions({
queryKey: key,
queryFn: () => Promise.resolve('string'),
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('infiniteQueryOptions', () => {
})

it('should tag the queryKey with the result type of the QueryFn', () => {
const key = queryKey()
const key = createKey()
const { queryKey: tagged } = infiniteQueryOptions({
queryKey: key,
queryFn: () => Promise.resolve('string'),
Expand All @@ -147,7 +147,7 @@ describe('infiniteQueryOptions', () => {
})

it('should tag the queryKey even if no promise is returned', () => {
const key = queryKey()
const key = createKey()
const { queryKey: tagged } = infiniteQueryOptions({
queryKey: key,
queryFn: () => 'string',
Expand All @@ -159,7 +159,7 @@ describe('infiniteQueryOptions', () => {
})

it('should tag the queryKey with the result type of the QueryFn if select is used', () => {
const key = queryKey()
const key = createKey()
const { queryKey: tagged } = infiniteQueryOptions({
queryKey: key,
queryFn: () => Promise.resolve('string'),
Expand All @@ -172,7 +172,7 @@ describe('infiniteQueryOptions', () => {
})

it('should return the proper type when passed to getQueryData', () => {
const key = queryKey()
const key = createKey()
const { queryKey: tagged } = infiniteQueryOptions({
queryKey: key,
queryFn: () => Promise.resolve('string'),
Expand All @@ -189,7 +189,7 @@ describe('infiniteQueryOptions', () => {
})

it('should properly type when passed to setQueryData', () => {
const key = queryKey()
const key = createKey()
const { queryKey: tagged } = infiniteQueryOptions({
queryKey: key,
queryFn: () => Promise.resolve('string'),
Expand All @@ -211,7 +211,7 @@ describe('infiniteQueryOptions', () => {
})

it('should not be allowed to be passed to non-infinite query functions', () => {
const key = queryKey()
const key = createKey()
const queryClient = new QueryClient()
const options = infiniteQueryOptions({
queryKey: key,
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('infiniteQueryOptions', () => {
})

it('should allow optional initialData function', () => {
const key = queryKey()
const key = createKey()
const initialData: { example: boolean } | undefined = { example: true }
const queryOptions = infiniteQueryOptions({
queryKey: key,
Expand All @@ -266,7 +266,7 @@ describe('infiniteQueryOptions', () => {
})

it('should allow optional initialData object', () => {
const key = queryKey()
const key = createKey()
const initialData: { example: boolean } | undefined = { example: true }
const queryOptions = infiniteQueryOptions({
queryKey: key,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { describe, expect, it } from 'vitest'
import { queryKey } from '@tanstack/query-test-utils'
import { createKey } from '@tanstack/query-test-utils'

import { infiniteQueryOptions } from '../infinite-query-options'
import type { CreateInfiniteQueryOptions } from '../types'

describe('infiniteQueryOptions', () => {
it('should return the object received as a parameter without any modification.', () => {
const key = queryKey()
const key = createKey()
const object: CreateInfiniteQueryOptions = {
queryKey: key,
queryFn: () => Promise.resolve(5),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TestBed } from '@angular/core/testing'
import { afterEach, beforeEach, describe, expectTypeOf, it, vi } from 'vitest'
import { provideZonelessChangeDetection } from '@angular/core'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import { createKey, sleep } from '@tanstack/query-test-utils'
import {
QueryClient,
injectInfiniteQuery,
Expand Down Expand Up @@ -29,7 +29,7 @@ describe('injectInfiniteQuery', () => {
})

it('should narrow type after isSuccess', () => {
const key = queryKey()
const key = createKey()
const query = TestBed.runInInjectionContext(() => {
return injectInfiniteQuery(() => ({
queryKey: key,
Expand All @@ -47,7 +47,7 @@ describe('injectInfiniteQuery', () => {
})

it('should work when queryFn is skipToken', () => {
const key = queryKey()
const key = createKey()
const query = TestBed.runInInjectionContext(() => {
return injectInfiniteQuery(() => ({
queryKey: key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
signal,
} from '@angular/core'
import { render } from '@testing-library/angular'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import { createKey, sleep } from '@tanstack/query-test-utils'
import {
QueryClient,
injectInfiniteQuery,
Expand All @@ -34,7 +34,7 @@ describe('injectInfiniteQuery', () => {
})

it('should properly execute infinite query', async () => {
const key = queryKey()
const key = createKey()

@Component({
template: `
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('injectInfiniteQuery', () => {
})

it('should reject and update signal', async () => {
const key = queryKey()
const key = createKey()

@Component({
template: `
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('injectInfiniteQuery', () => {
})

it('should keep initialData visible alongside the error when a refetch fails', async () => {
const key = queryKey()
const key = createKey()

@Component({
template: `
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('injectInfiniteQuery', () => {

describe('skipToken', () => {
it('should not fetch when queryFn is skipToken, and fetch once it is replaced', async () => {
const key = queryKey()
const key = createKey()
const queryFn = vi.fn<
(context: { pageParam: number }) => Promise<string>
>(({ pageParam }: { pageParam: number }) =>
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('injectInfiniteQuery', () => {

describe('injection context', () => {
it('should throw NG0203 with descriptive error outside injection context', () => {
const key = queryKey()
const key = createKey()
expect(() => {
injectInfiniteQuery(() => ({
queryKey: key,
Expand All @@ -202,7 +202,7 @@ describe('injectInfiniteQuery', () => {
})

it('should be usable outside injection context when passing an injector', () => {
const key = queryKey()
const key = createKey()
const query = injectInfiniteQuery(
() => ({
queryKey: key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
provideZonelessChangeDetection,
} from '@angular/core'
import { render } from '@testing-library/angular'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import { createKey, sleep } from '@tanstack/query-test-utils'
import {
QueryClient,
injectIsFetching,
Expand Down Expand Up @@ -34,7 +34,7 @@ describe('injectIsFetching', () => {
})

it('should return the number of fetching queries', async () => {
const key = queryKey()
const key = createKey()

@Component({
template: `<div>fetching: {{ isFetching() }}</div>`,
Expand All @@ -59,8 +59,8 @@ describe('injectIsFetching', () => {
})

it('should be able to filter by queryKey', async () => {
const key1 = queryKey()
const key2 = queryKey()
const key1 = createKey()
const key2 = createKey()

@Component({
template: `<div>fetching: {{ isFetching() }}</div>`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
provideZonelessChangeDetection,
} from '@angular/core'
import { render } from '@testing-library/angular'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import { createKey, sleep } from '@tanstack/query-test-utils'
import {
QueryClient,
injectIsMutating,
Expand Down Expand Up @@ -34,7 +34,7 @@ describe('injectIsMutating', () => {
})

it('should properly return isMutating state', async () => {
const key = queryKey()
const key = createKey()

@Component({
template: `<div>mutating: {{ isMutating() }}</div>`,
Expand All @@ -61,8 +61,8 @@ describe('injectIsMutating', () => {
})

it('should be able to filter by mutationKey', async () => {
const key1 = queryKey()
const key2 = queryKey()
const key1 = createKey()
const key2 = createKey()

@Component({
template: `<div>mutating: {{ isMutating() }}</div>`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { TestBed } from '@angular/core/testing'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { By } from '@angular/platform-browser'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import { createKey, sleep } from '@tanstack/query-test-utils'
import {
QueryClient,
injectMutation,
Expand Down Expand Up @@ -37,7 +37,7 @@ describe('injectMutationState', () => {

describe('injectMutationState', () => {
it('should return variables after calling mutate 1', () => {
const mutationKey = queryKey()
const mutationKey = createKey()
const variables = 'foo123'

const mutation = TestBed.runInInjectionContext(() => {
Expand All @@ -60,8 +60,8 @@ describe('injectMutationState', () => {
})

it('should update injectMutationState when reactive options change', () => {
const mutationKey1 = queryKey()
const mutationKey2 = queryKey()
const mutationKey1 = createKey()
const mutationKey2 = createKey()
const variables1 = 'foo123'
const variables2 = 'bar234'

Expand Down Expand Up @@ -98,7 +98,7 @@ describe('injectMutationState', () => {

it('should return variables after calling mutate 2', () => {
queryClient.clear()
const mutationKey = queryKey()
const mutationKey = createKey()
const variables = 'bar234'

const mutation = TestBed.runInInjectionContext(() => {
Expand Down
Loading
Loading