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
7 changes: 7 additions & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ export default [
"no-unused-vars": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"@typescript-eslint/ban-ts-comment": "off",
"prettier/prettier": ["warn", { printWidth: 88 }],
},
Expand Down
4 changes: 2 additions & 2 deletions src/api/__tests__/run-property-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useQuery, useSubscription } from "@urql/vue";
import type { UseQueryResponse, UseSubscriptionResponse } from "@urql/vue";
import fc from "fast-check";

import { mockUseQueryResponse, mockUseSubscriptionResponse } from "@/graphql/tests";

import { fcMockUseQueryResponseArg, fcMockUseSubscriptionResponseArg } from "./fc";
import { mockUseQueryResponse } from "./mock-use-query-response";
import { mockUseSubscriptionResponse } from "./mock-use-subscription-response";

interface _UseSubscribeXXXReturn<R> {
data: ComputedRef<R | undefined>;
Expand Down
3 changes: 1 addition & 2 deletions src/api/__tests__/scratch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { fromValue, makeSubject, never } from "wonka";

import type { CtrlStateQuery } from "@/graphql/codegen/generated";
import { useCtrlStateQuery } from "@/graphql/codegen/generated";

import { useInSetupWithUrqlClient } from "./setup-with-client";
import { useInSetupWithUrqlClient } from "@/graphql/tests";

function useQueryFromClient(client: MaybeRef<Client>) {
const disposable = useInSetupWithUrqlClient(
Expand Down
6 changes: 3 additions & 3 deletions src/api/__tests__/use-mapped-with-fallback.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describe, expect, it } from "vitest";
import fc from "fast-check";

import { useMappedWithFallback } from "../use-mapped-with-fallback";
import { mockUseQueryResponse } from "@/graphql/tests";
import { mockUseSubscriptionResponse } from "@/graphql/tests/mock-use-subscription-response";

import { mockUseQueryResponse } from "./mock-use-query-response";
import { mockUseSubscriptionResponse } from "./mock-use-subscription-response";
import { useMappedWithFallback } from "../use-mapped-with-fallback";

type QueryData = { ctrl: { state: string } };
type SubscriptionData = { ctrlState: string };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
import { describe, expect, it } from "vitest";
import type { App, MaybeRef } from "vue";
import { createApp, defineComponent, ref } from "vue";
import { Client, CombinedError, provideClient, useQuery } from "@urql/vue";
import type { MaybeRef } from "vue";
import { ref } from "vue";
import { Client, CombinedError, useQuery } from "@urql/vue";
import gql from "graphql-tag";
import { fromValue, never } from "wonka";

type SetupFunction = () => Record<string, unknown>;

interface WitSetupsOptions {
setupParent: SetupFunction;
setupChild: SetupFunction;
}

class DisposableApp implements Disposable {
constructor(private app: App) {}

[Symbol.dispose]() {
this.app.unmount();
}
}

function withSetups(options: WitSetupsOptions) {
const ParentComponent = defineComponent({
setup: options.setupParent,
template: "<child-component />",
});

const ChildComponent = defineComponent({
setup: options.setupChild,
template: "<template />",
});

const app = createApp(ParentComponent);
app.component("ChildComponent", ChildComponent);
app.mount(document.createElement("div"));
const disposable = new DisposableApp(app);
return { app, [Symbol.dispose]: () => disposable[Symbol.dispose]() };
}
import { useInSetupWithUrqlClient } from "@/graphql/tests";

export const FooDocument = gql`
query foo {
Expand All @@ -50,19 +19,11 @@ export type FooQuery = {
};

function useQueryFromClient(client: MaybeRef<Client>) {
let query: ReturnType<typeof useQuery<FooQuery>> | undefined;
const app = withSetups({
setupParent() {
provideClient(client);
return {};
},
setupChild() {
query = useQuery<FooQuery>({ query: FooDocument });
return {};
},
});
if (!query) throw new Error("query is undefined");
return { ...app, query, [Symbol.dispose]: () => app[Symbol.dispose]() };
const { ret: query, [Symbol.dispose]: dispose } = useInSetupWithUrqlClient(
() => useQuery<FooQuery>({ query: FooDocument }),
client,
);
return { query, [Symbol.dispose]: () => dispose() };
}

describe("one", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { UseQueryResponse } from "@urql/vue";
import gql from "graphql-tag";
import fc from "fast-check";

import { mockUseQueryResponse } from "./mock-use-query-response";
import { mockUseQueryResponse } from "..";

vi.mock("@urql/vue", () => ({
useQuery: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { UseSubscriptionResponse } from "@urql/vue";
import gql from "graphql-tag";
import fc from "fast-check";

import { mockUseSubscriptionResponse } from "./mock-use-subscription-response";
import { mockUseSubscriptionResponse } from "..";

vi.mock("@urql/vue", () => ({
useSubscription: vi.fn(),
Expand Down
3 changes: 3 additions & 0 deletions src/graphql/tests/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./mock-use-query-response";
export * from "./mock-use-subscription-response"
export * from "./setup-with-client";
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { MaybeRef } from "vue";
import type { Client } from "@urql/vue";
import { provideClient, useClientHandle } from "@urql/vue";
import { createClient, provideClient, useClientHandle } from "@urql/vue";

import { setupNestedComponents } from "./setup-nested-components";
import { setupNestedComponents } from "@/tests/vue";

/**
* Execute `func` in a Vue component `setup` in which the `client` can be injected.
Expand All @@ -29,8 +29,11 @@ export function useInSetupWithUrqlClient<T>(func: () => T, client: MaybeRef<Clie
if (import.meta.vitest) {
const { it, expect } = import.meta.vitest;

it.skip("useInSetupWithUrqlClient", () => {
const mockClient = {} as Client;
it("useInSetupWithUrqlClient", () => {
const mockClient = createClient({
url: "http://example.com/graphql",
exchanges: [],
});

using ret = useInSetupWithUrqlClient(() => useClientHandle(), mockClient);
const { ret: handle } = ret;
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/tests/vue/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./app-disposer";
export * from "./setup-nested-components";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createApp, defineComponent, inject, provide } from "vue";

import { AppDisposer } from "./app-disposer";
import { AppDisposer } from "@/tests/vue";

type SetupFunction = () => Record<string, unknown>;

Expand Down
Loading