synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
728 lines (727 loc) • 16.8 kB
JavaScript
import P from "lodash-es/noop";
import { useState as v } from "react";
function E() {
const e = vi.fn();
let s = null;
const l = (a) => {
if (s) {
const r = {
data: a,
status: "success",
isSuccess: !0,
isPending: !1,
isLoading: !1,
isError: !1,
error: null,
isFetched: !0,
isFetchedAfterMount: !0,
isFetching: !1,
isInitialLoading: !1,
isLoadingError: !1,
isRefetchError: !1,
isRefetching: !1,
fetchStatus: "idle",
isPaused: !1,
dataUpdatedAt: Date.now(),
errorUpdatedAt: 0,
errorUpdateCount: 0,
failureCount: 0,
failureReason: null,
refetch: e,
isPlaceholderData: !1,
isStale: !1,
promise: Promise.resolve(a)
};
s(r);
} else
console.warn(
"setSuccess called before mock query was rendered or setValue was captured."
);
}, i = (a) => {
if (s) {
const r = {
data: void 0,
dataUpdatedAt: 0,
error: a,
errorUpdateCount: 1,
errorUpdatedAt: Date.now(),
failureCount: 1,
isError: !0,
isFetched: !1,
isFetchedAfterMount: !0,
isFetching: !1,
isLoadingError: !0,
isPlaceholderData: !1,
isRefetchError: !1,
isRefetching: !1,
isStale: !1,
isSuccess: !1,
refetch: e,
status: "error",
failureReason: null,
fetchStatus: "idle",
isInitialLoading: !1,
isPaused: !1,
isLoading: !1,
isPending: !1,
promise: new Promise(() => {
})
};
s(r);
} else
console.warn(
"setError called before mock query was rendered or setValue was captured."
);
}, o = () => {
if (s) {
const a = {
data: void 0,
dataUpdatedAt: Date.now(),
error: null,
errorUpdateCount: 0,
errorUpdatedAt: 0,
failureCount: 0,
isError: !1,
isFetched: !0,
isFetchedAfterMount: !0,
isFetching: !0,
isLoading: !0,
isLoadingError: !1,
isPlaceholderData: !1,
isRefetchError: !1,
isRefetching: !1,
isStale: !1,
isSuccess: !1,
refetch: e,
status: "pending",
failureReason: null,
fetchStatus: "fetching",
isPending: !0,
isInitialLoading: !0,
isPaused: !1,
promise: new Promise(() => {
})
};
s(a);
} else
console.warn(
"setError called before mock query was rendered or setValue was captured."
);
};
function c() {
if (s) {
const a = {
data: void 0,
dataUpdatedAt: 0,
error: null,
errorUpdateCount: 1,
errorUpdatedAt: Date.now(),
failureCount: 1,
isError: !1,
isFetched: !1,
isFetchedAfterMount: !1,
isFetching: !1,
isLoadingError: !1,
isPlaceholderData: !1,
isRefetchError: !1,
isRefetching: !1,
isStale: !1,
isSuccess: !1,
refetch: e,
status: "pending",
failureReason: null,
fetchStatus: "idle",
isInitialLoading: !1,
isPaused: !0,
isLoading: !1,
isPending: !0,
promise: new Promise(() => {
})
};
s(a);
} else
console.warn(
"setIdle called before mock query was rendered or setValue was captured."
);
}
return {
mock: vi.fn(function() {
const [r, n] = v({
data: void 0,
fetchStatus: "fetching",
dataUpdatedAt: 0,
error: null,
errorUpdateCount: 0,
errorUpdatedAt: 0,
failureCount: 0,
failureReason: null,
isError: !1,
isFetched: !1,
isFetchedAfterMount: !1,
isFetching: !1,
isInitialLoading: !1,
isLoading: !0,
isLoadingError: !1,
isPaused: !1,
isPending: !0,
isPlaceholderData: !1,
isRefetchError: !1,
isRefetching: !1,
isStale: !1,
isSuccess: !1,
refetch: e,
status: "pending",
promise: new Promise(() => {
})
});
return s = n, r;
}),
mockRefetch: e,
setSuccess: l,
setError: i,
setLoading: o,
setIdle: c
};
}
function F(e) {
return {
data: e,
dataUpdatedAt: Date.now(),
error: null,
errorUpdateCount: 0,
errorUpdatedAt: 0,
failureCount: 0,
isError: !1,
isFetched: !0,
isFetchedAfterMount: !0,
isFetching: !1,
isLoading: !1,
isLoadingError: !1,
isPlaceholderData: !1,
isRefetchError: !1,
isRefetching: !1,
isStale: !1,
isSuccess: !0,
refetch: P,
status: "success",
failureReason: null,
fetchStatus: "idle",
isInitialLoading: !1,
isPaused: !1,
isPending: !1,
promise: Promise.resolve(e)
};
}
function w() {
return {
data: void 0,
dataUpdatedAt: Date.now(),
error: null,
errorUpdateCount: 0,
errorUpdatedAt: 0,
failureCount: 0,
isError: !1,
isFetched: !0,
isFetchedAfterMount: !0,
isFetching: !0,
isLoading: !0,
isLoadingError: !1,
isPlaceholderData: !1,
isRefetchError: !1,
isRefetching: !1,
isStale: !1,
isSuccess: !1,
refetch: P,
status: "pending",
failureReason: null,
fetchStatus: "fetching",
isPending: !0,
isInitialLoading: !0,
isPaused: !1,
promise: new Promise(() => {
})
};
}
function A(e) {
return {
data: void 0,
dataUpdatedAt: 0,
error: e,
errorUpdateCount: 1,
errorUpdatedAt: Date.now(),
failureCount: 1,
isError: !0,
isFetched: !1,
isFetchedAfterMount: !0,
isFetching: !1,
isLoadingError: !0,
isPlaceholderData: !1,
isRefetchError: !1,
isRefetching: !1,
isStale: !1,
isSuccess: !1,
refetch: vi.fn(),
status: "error",
failureReason: null,
fetchStatus: "idle",
isInitialLoading: !1,
isPaused: !1,
isLoading: !1,
isPending: !1,
promise: void 0
};
}
function R() {
return {
data: void 0,
dataUpdatedAt: 0,
error: null,
errorUpdateCount: 1,
errorUpdatedAt: Date.now(),
failureCount: 1,
isError: !1,
isFetched: !1,
isFetchedAfterMount: !1,
isFetching: !1,
isLoadingError: !1,
isPlaceholderData: !1,
isRefetchError: !1,
isRefetching: !1,
isStale: !1,
isSuccess: !1,
refetch: P,
status: "pending",
failureReason: null,
fetchStatus: "idle",
isInitialLoading: !1,
isPaused: !0,
isLoading: !1,
isPending: !0,
promise: new Promise(() => {
})
};
}
function U() {
let e = null;
function s(t) {
e ? e(
(u) => ({
...u,
variables: t
})
) : console.warn(
"mutate or mutateAsync called before mock mutation was rendered or setValue was captured."
);
}
const l = vi.fn(), i = vi.fn(), o = vi.fn(), c = l.mock.lastCall?.[0] || i.mock.lastCall?.[0];
function f(t) {
return s(t), l(t);
}
function a(t) {
return s(t), i(t);
}
const r = (t) => {
if (e) {
const u = {
data: t,
mutate: f,
mutateAsync: a,
reset: o,
context: void 0,
error: null,
failureCount: 0,
isError: !1,
isIdle: !1,
isPaused: !1,
isSuccess: !0,
status: "success",
variables: c,
failureReason: null,
isPending: !1,
submittedAt: 0
};
e(
(g) => ({ ...u, variables: g.variables })
);
} else
console.warn(
"setSuccess called before mock mutation was rendered or setValue was captured."
);
}, n = (t) => {
if (e) {
const u = {
error: t,
data: void 0,
mutate: f,
mutateAsync: a,
reset: o,
context: void 0,
failureCount: 1,
isError: !0,
isIdle: !1,
isPaused: !1,
isSuccess: !1,
status: "error",
variables: c,
failureReason: t,
isPending: !1,
submittedAt: 0
};
e(
(g) => ({ ...u, variables: g.variables })
);
} else
console.warn(
"setError called before mock mutation was rendered or setValue was captured."
);
}, d = () => {
if (e) {
const t = {
data: void 0,
error: null,
mutate: f,
mutateAsync: a,
reset: o,
context: void 0,
failureCount: 0,
isError: !1,
isIdle: !1,
isPaused: !1,
isSuccess: !1,
status: "pending",
failureReason: null,
isPending: !0,
submittedAt: 0,
variables: c
};
e(
(u) => ({ ...t, variables: u.variables })
);
} else
console.warn(
"setPending called before mock mutation was rendered or setValue was captured."
);
};
function h() {
e ? e({
data: void 0,
error: null,
mutate: f,
mutateAsync: a,
reset: o,
variables: void 0,
context: void 0,
failureCount: 0,
isError: !1,
isIdle: !0,
isPaused: !1,
isSuccess: !1,
status: "idle",
failureReason: null,
isPending: !1,
submittedAt: 0
}) : console.warn(
"setIdle called before mock mutation was rendered or setValue was captured."
);
}
return {
mock: vi.fn(function() {
const [u, g] = v({
data: void 0,
error: null,
mutate: f,
mutateAsync: a,
reset: o,
variables: void 0,
context: void 0,
failureCount: 0,
isError: !1,
isIdle: !0,
isPaused: !1,
isSuccess: !1,
status: "idle",
failureReason: null,
isPending: !1,
submittedAt: 0
});
return e = g, u;
}),
mockMutate: l,
mockMutateAsync: i,
mockReset: o,
setSuccess: r,
setError: n,
setPending: d,
setIdle: h
};
}
function L(e) {
return {
context: void 0,
data: void 0,
error: null,
failureCount: 0,
isError: !1,
isIdle: !0,
isPaused: !1,
isSuccess: !1,
mutate: vi.fn(),
mutateAsync: vi.fn().mockResolvedValue(e),
reset: vi.fn(),
status: "idle",
variables: void 0,
failureReason: null,
isPending: !1,
submittedAt: 0
};
}
function k(e, s) {
return {
context: void 0,
data: void 0,
error: null,
failureCount: 0,
isError: !1,
isIdle: !1,
isPaused: !1,
isSuccess: !1,
mutate: vi.fn(),
mutateAsync: vi.fn().mockResolvedValue(e),
reset: vi.fn(),
status: "pending",
variables: s,
failureReason: null,
isPending: !0,
submittedAt: 0
};
}
function C(e, s = !1) {
return {
data: {
pages: e
},
error: null,
isError: !1,
isPending: !1,
isLoading: !1,
isLoadingError: !1,
isRefetchError: !1,
isSuccess: !0,
status: "success",
fetchNextPage: vi.fn(),
fetchPreviousPage: vi.fn(),
hasNextPage: s,
hasPreviousPage: !1,
isFetchingNextPage: !1,
isFetchingPreviousPage: !1,
dataUpdatedAt: 0,
errorUpdatedAt: 0,
failureCount: 0,
failureReason: null,
errorUpdateCount: 0,
isFetched: !1,
isFetchedAfterMount: !1,
isFetching: !1,
isInitialLoading: !1,
isPaused: !1,
isPlaceholderData: !1,
isRefetching: !1,
isStale: !1,
refetch: vi.fn(),
fetchStatus: "idle",
isFetchNextPageError: !1,
isFetchPreviousPageError: !1,
promise: Promise.resolve({ pages: e })
};
}
function M() {
const e = vi.fn(), s = vi.fn(), l = vi.fn();
let i = null;
const o = (r, n = !1, d = !1) => {
if (i) {
const h = {
data: { pages: r, pageParams: [] },
hasNextPage: n,
status: "success",
isSuccess: !0,
isPending: !1,
isLoading: !1,
isError: !1,
error: null,
isFetched: !0,
isFetchedAfterMount: !0,
isFetching: !1,
isInitialLoading: !1,
isLoadingError: !1,
isRefetchError: !1,
isRefetching: !1,
fetchStatus: d ? "fetching" : "idle",
isPaused: !1,
dataUpdatedAt: Date.now(),
errorUpdatedAt: 0,
errorUpdateCount: 0,
failureCount: 0,
failureReason: null,
fetchNextPage: e,
fetchPreviousPage: s,
refetch: l,
hasPreviousPage: !1,
isFetchingNextPage: d,
isFetchingPreviousPage: !1,
isPlaceholderData: !1,
isStale: !1,
isFetchPreviousPageError: !1,
isFetchNextPageError: !1,
promise: Promise.resolve({ pages: r, pageParams: [] })
};
i(h);
} else
console.warn(
"setSuccess called before useInfiniteQueryMock was rendered or setValue was captured."
);
}, c = (r) => {
if (i) {
const n = {
data: void 0,
hasNextPage: !1,
status: "error",
isSuccess: !1,
isPending: !1,
isLoading: !1,
isError: !0,
error: r,
isFetched: !0,
isFetchedAfterMount: !0,
isFetching: !1,
isInitialLoading: !1,
isLoadingError: !0,
isRefetchError: !1,
isRefetching: !1,
fetchStatus: "idle",
isPaused: !1,
dataUpdatedAt: Date.now(),
errorUpdatedAt: 0,
errorUpdateCount: 0,
failureCount: 0,
failureReason: null,
fetchNextPage: e,
fetchPreviousPage: s,
refetch: l,
hasPreviousPage: !1,
isFetchingNextPage: !1,
isFetchingPreviousPage: !1,
isPlaceholderData: !1,
isStale: !1,
isFetchNextPageError: !1,
isFetchPreviousPageError: !1,
promise: new Promise(() => {
})
};
i(n);
} else
console.warn(
"setError called before useInfiniteQueryMock was rendered or setValue was captured."
);
}, f = () => {
if (i) {
const r = {
data: void 0,
hasNextPage: !1,
status: "pending",
isSuccess: !1,
isPending: !0,
isLoading: !0,
isError: !1,
error: null,
isFetched: !0,
isFetchedAfterMount: !0,
isFetching: !1,
isInitialLoading: !1,
isLoadingError: !1,
isRefetchError: !1,
isRefetching: !1,
fetchStatus: "fetching",
isPaused: !1,
dataUpdatedAt: Date.now(),
errorUpdatedAt: 0,
errorUpdateCount: 0,
failureCount: 0,
failureReason: null,
fetchNextPage: e,
fetchPreviousPage: s,
refetch: l,
hasPreviousPage: !1,
isFetchingNextPage: !0,
isFetchingPreviousPage: !1,
isPlaceholderData: !1,
isStale: !1,
isFetchNextPageError: !1,
isFetchPreviousPageError: !1,
promise: new Promise(() => {
})
};
i(r);
} else
console.warn(
"setError called before useInfiniteQueryMock was rendered or setValue was captured."
);
};
return {
mock: vi.fn(function() {
const [n, d] = v({
data: void 0,
fetchStatus: "fetching",
dataUpdatedAt: 0,
error: null,
errorUpdateCount: 0,
errorUpdatedAt: 0,
failureCount: 0,
failureReason: null,
fetchNextPage: e,
fetchPreviousPage: s,
hasNextPage: !1,
hasPreviousPage: !1,
isError: !1,
isFetched: !1,
isFetchedAfterMount: !1,
isFetching: !1,
isFetchingNextPage: !1,
isFetchingPreviousPage: !1,
isInitialLoading: !1,
isLoading: !0,
isLoadingError: !1,
isPaused: !1,
isPending: !0,
isPlaceholderData: !1,
isRefetchError: !1,
isRefetching: !1,
isStale: !1,
isSuccess: !1,
refetch: l,
status: "pending",
isFetchNextPageError: !1,
isFetchPreviousPageError: !1,
promise: new Promise(() => {
})
});
return i = d, n;
}),
mockFetchNextPage: e,
setSuccess: o,
setError: c,
setLoading: f
};
}
export {
M as getUseInfiniteQueryMock,
C as getUseInfiniteQuerySuccessMock,
L as getUseMutationIdleMock,
U as getUseMutationMock,
k as getUseMutationPendingMock,
A as getUseQueryErrorMock,
R as getUseQueryIdleMock,
w as getUseQueryLoadingMock,
E as getUseQueryMock,
F as getUseQuerySuccessMock
};
//# sourceMappingURL=ReactQueryMockUtils.js.map