@trackunit/react-core-contexts-test 0.1.112 → 0.1.114
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs2.js +16 -1
- package/index.esm2.js +16 -1
- package/package.json +3 -3
- package/src/utils/queryFor.d.ts +24 -5
package/index.cjs2.js
CHANGED
|
@@ -43995,8 +43995,22 @@ const trackunitProviders = () => new TrackunitProvidersMockBuilder();
|
|
|
43995
43995
|
* Note that *all* properties should be given a value, use `null` in place of `undefined`,
|
|
43996
43996
|
* otherwise nothing will be returned.
|
|
43997
43997
|
* @param error ApolloError object to be returned.
|
|
43998
|
-
* @returns {MockedResponse}
|
|
43998
|
+
* @returns {MockedResponse} with data attached, this response can be passed to the mocked ApolloProvider.
|
|
43999
43999
|
* @see [Testing React components using MockedProvider and associated APIs](https://www.apollographql.com/docs/react/development-testing/testing/)
|
|
44000
|
+
* @example
|
|
44001
|
+
* it("should show the brand fetched from graphql", async () => {
|
|
44002
|
+
* const mock = queryFor(GetDemoAssetDocument, {
|
|
44003
|
+
* assetId: "assetId",
|
|
44004
|
+
* });
|
|
44005
|
+
*
|
|
44006
|
+
* AssetRuntime.getAssetInfo = jest.fn().mockResolvedValue({ assetId: "assetId" });
|
|
44007
|
+
* await trackunitProviders()
|
|
44008
|
+
* .apollo([mock])
|
|
44009
|
+
* .render(<App />);
|
|
44010
|
+
*
|
|
44011
|
+
* # mock.data is the combined result of what is passed in from queryFor and what is generated by generateMockData
|
|
44012
|
+
* expect(screen.getByText(`Brand: ${mock.data.asset?.brand}`)).toBeInTheDocument();
|
|
44013
|
+
* });
|
|
44000
44014
|
*/
|
|
44001
44015
|
const queryFor = (document, variables, data, error) => {
|
|
44002
44016
|
return {
|
|
@@ -44004,6 +44018,7 @@ const queryFor = (document, variables, data, error) => {
|
|
|
44004
44018
|
query: document,
|
|
44005
44019
|
variables,
|
|
44006
44020
|
},
|
|
44021
|
+
data,
|
|
44007
44022
|
newData: () => {
|
|
44008
44023
|
if (process.env.VSCODE_INSPECTOR_OPTIONS || process.env.DEBUG) {
|
|
44009
44024
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/index.esm2.js
CHANGED
|
@@ -43967,8 +43967,22 @@ const trackunitProviders = () => new TrackunitProvidersMockBuilder();
|
|
|
43967
43967
|
* Note that *all* properties should be given a value, use `null` in place of `undefined`,
|
|
43968
43968
|
* otherwise nothing will be returned.
|
|
43969
43969
|
* @param error ApolloError object to be returned.
|
|
43970
|
-
* @returns {MockedResponse}
|
|
43970
|
+
* @returns {MockedResponse} with data attached, this response can be passed to the mocked ApolloProvider.
|
|
43971
43971
|
* @see [Testing React components using MockedProvider and associated APIs](https://www.apollographql.com/docs/react/development-testing/testing/)
|
|
43972
|
+
* @example
|
|
43973
|
+
* it("should show the brand fetched from graphql", async () => {
|
|
43974
|
+
* const mock = queryFor(GetDemoAssetDocument, {
|
|
43975
|
+
* assetId: "assetId",
|
|
43976
|
+
* });
|
|
43977
|
+
*
|
|
43978
|
+
* AssetRuntime.getAssetInfo = jest.fn().mockResolvedValue({ assetId: "assetId" });
|
|
43979
|
+
* await trackunitProviders()
|
|
43980
|
+
* .apollo([mock])
|
|
43981
|
+
* .render(<App />);
|
|
43982
|
+
*
|
|
43983
|
+
* # mock.data is the combined result of what is passed in from queryFor and what is generated by generateMockData
|
|
43984
|
+
* expect(screen.getByText(`Brand: ${mock.data.asset?.brand}`)).toBeInTheDocument();
|
|
43985
|
+
* });
|
|
43972
43986
|
*/
|
|
43973
43987
|
const queryFor = (document, variables, data, error) => {
|
|
43974
43988
|
return {
|
|
@@ -43976,6 +43990,7 @@ const queryFor = (document, variables, data, error) => {
|
|
|
43976
43990
|
query: document,
|
|
43977
43991
|
variables,
|
|
43978
43992
|
},
|
|
43993
|
+
data,
|
|
43979
43994
|
newData: () => {
|
|
43980
43995
|
if (process.env.VSCODE_INSPECTOR_OPTIONS || process.env.DEBUG) {
|
|
43981
43996
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-contexts-test",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.114",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"main": "./index.cjs.js",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@apollo/client": "3.7.10",
|
|
13
|
-
"@trackunit/react-core-contexts-api": "0.2.
|
|
14
|
-
"@trackunit/react-core-hooks": "0.2.
|
|
13
|
+
"@trackunit/react-core-contexts-api": "0.2.60",
|
|
14
|
+
"@trackunit/react-core-hooks": "0.2.99",
|
|
15
15
|
"graphql": "15.8.0",
|
|
16
16
|
"lodash": "4.17.21",
|
|
17
17
|
"react": "18.2.0",
|
package/src/utils/queryFor.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { ApolloError, OperationVariables, QueryHookOptions, useLazyQuery, useQuery } from "@apollo/client";
|
|
1
|
+
import { ApolloError, OperationVariables, QueryHookOptions, TypedDocumentNode, useLazyQuery, useQuery } from "@apollo/client";
|
|
2
2
|
import { MockedResponse } from "@apollo/client/testing";
|
|
3
|
-
|
|
3
|
+
export type DeepPartialNullable<T> = T extends any[] ? DeepPartialNullableArray<T[number]> : T extends object ? {
|
|
4
|
+
[P in keyof T]?: DeepPartialNullable<T[P]> | null;
|
|
5
|
+
} : T | null;
|
|
6
|
+
type DeepPartialNullableArray<T> = DeepPartialNullable<T>[];
|
|
4
7
|
/**
|
|
5
8
|
*
|
|
6
9
|
* @param document Document that represents the specific GQL query / mutation schema.
|
|
@@ -10,10 +13,26 @@ import { DocumentNode } from "graphql";
|
|
|
10
13
|
* Note that *all* properties should be given a value, use `null` in place of `undefined`,
|
|
11
14
|
* otherwise nothing will be returned.
|
|
12
15
|
* @param error ApolloError object to be returned.
|
|
13
|
-
* @returns {MockedResponse}
|
|
16
|
+
* @returns {MockedResponse} with data attached, this response can be passed to the mocked ApolloProvider.
|
|
14
17
|
* @see [Testing React components using MockedProvider and associated APIs](https://www.apollographql.com/docs/react/development-testing/testing/)
|
|
18
|
+
* @example
|
|
19
|
+
* it("should show the brand fetched from graphql", async () => {
|
|
20
|
+
* const mock = queryFor(GetDemoAssetDocument, {
|
|
21
|
+
* assetId: "assetId",
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* AssetRuntime.getAssetInfo = jest.fn().mockResolvedValue({ assetId: "assetId" });
|
|
25
|
+
* await trackunitProviders()
|
|
26
|
+
* .apollo([mock])
|
|
27
|
+
* .render(<App />);
|
|
28
|
+
*
|
|
29
|
+
* # mock.data is the combined result of what is passed in from queryFor and what is generated by generateMockData
|
|
30
|
+
* expect(screen.getByText(`Brand: ${mock.data.asset?.brand}`)).toBeInTheDocument();
|
|
31
|
+
* });
|
|
15
32
|
*/
|
|
16
|
-
export declare const queryFor: <TData, TVariables extends OperationVariables = OperationVariables>(document:
|
|
33
|
+
export declare const queryFor: <TData, TVariables extends OperationVariables = OperationVariables>(document: TypedDocumentNode<TData, TVariables>, variables: TVariables, data?: TData | null | undefined, error?: ApolloError | Error) => MockedResponse<TData, Record<string, any>> & {
|
|
34
|
+
data: NonNullable<TData>;
|
|
35
|
+
};
|
|
17
36
|
type QueryReturn<TData, TVariables extends OperationVariables = OperationVariables> = ReturnType<typeof useQuery<TData, TVariables>>;
|
|
18
37
|
type QueryLazyReturn<TData, TVariables extends OperationVariables = OperationVariables> = ReturnType<typeof useLazyQuery<TData, TVariables>>;
|
|
19
38
|
/**
|
|
@@ -28,5 +47,5 @@ type QueryLazyReturn<TData, TVariables extends OperationVariables = OperationVar
|
|
|
28
47
|
* @returns {MockedResponse} that can be passed to the mocked ApolloProvider.
|
|
29
48
|
* @see [Testing React components using MockedProvider and associated APIs](https://www.apollographql.com/docs/react/development-testing/testing/)
|
|
30
49
|
*/
|
|
31
|
-
export declare const queryForHook: <TData, TVariables extends OperationVariables = OperationVariables>(hookFn: (baseOptions: QueryHookOptions<TData, TVariables>) => import("@apollo/client").QueryResult<TData, TVariables> | import("@apollo/client").LazyQueryResultTuple<TData, TVariables>, document:
|
|
50
|
+
export declare const queryForHook: <TData, TVariables extends OperationVariables = OperationVariables>(hookFn: (baseOptions: QueryHookOptions<TData, TVariables>) => import("@apollo/client").QueryResult<TData, TVariables> | import("@apollo/client").LazyQueryResultTuple<TData, TVariables>, document: TypedDocumentNode<TData, TVariables>, variables: TVariables, data: TData | null, error?: ApolloError | Error) => MockedResponse;
|
|
32
51
|
export {};
|