@khanacademy/wonder-blocks-testing 7.1.10 → 7.1.12

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.
Files changed (142) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/es/index.js +183 -120
  3. package/dist/fetch/fetch-request-matches-mock.d.ts +5 -0
  4. package/dist/fetch/fetch-request-matches-mock.js.flow +17 -0
  5. package/dist/fetch/mock-fetch.d.ts +5 -0
  6. package/dist/fetch/mock-fetch.js.flow +13 -0
  7. package/dist/fetch/types.d.ts +9 -0
  8. package/dist/fetch/types.js.flow +19 -0
  9. package/dist/fixtures/fixtures.basic.stories.d.ts +13 -0
  10. package/dist/fixtures/fixtures.basic.stories.js.flow +22 -0
  11. package/dist/fixtures/fixtures.d.ts +19 -0
  12. package/dist/fixtures/fixtures.defaultwrapper.stories.d.ts +9 -0
  13. package/dist/fixtures/fixtures.defaultwrapper.stories.js.flow +17 -0
  14. package/dist/fixtures/fixtures.js.flow +33 -0
  15. package/dist/fixtures/types.d.ts +36 -0
  16. package/dist/fixtures/types.js.flow +37 -0
  17. package/dist/gql/gql-request-matches-mock.d.ts +3 -0
  18. package/dist/gql/gql-request-matches-mock.js.flow +15 -0
  19. package/dist/gql/mock-gql-fetch.d.ts +5 -0
  20. package/dist/gql/mock-gql-fetch.js.flow +13 -0
  21. package/dist/gql/types.d.ts +15 -0
  22. package/dist/gql/types.js.flow +39 -0
  23. package/dist/harness/adapters/adapters.d.ts +35 -0
  24. package/dist/harness/adapters/adapters.js.flow +69 -0
  25. package/dist/harness/adapters/css.d.ts +12 -0
  26. package/dist/harness/adapters/css.js.flow +23 -0
  27. package/dist/harness/adapters/data.d.ts +18 -0
  28. package/dist/harness/adapters/data.js.flow +32 -0
  29. package/dist/harness/adapters/portal.d.ts +12 -0
  30. package/dist/harness/adapters/portal.js.flow +18 -0
  31. package/dist/harness/adapters/router.d.ts +94 -0
  32. package/dist/harness/adapters/router.js.flow +122 -0
  33. package/dist/harness/hook-harness.d.ts +13 -0
  34. package/dist/harness/hook-harness.js.flow +23 -0
  35. package/dist/harness/make-hook-harness.d.ts +17 -0
  36. package/dist/harness/make-hook-harness.js.flow +42 -0
  37. package/dist/harness/make-test-harness.d.ts +18 -0
  38. package/dist/harness/make-test-harness.js.flow +48 -0
  39. package/dist/harness/render-adapters.d.ts +6 -0
  40. package/dist/harness/render-adapters.js.flow +24 -0
  41. package/dist/harness/test-harness.d.ts +32 -0
  42. package/dist/harness/test-harness.js.flow +83 -0
  43. package/dist/harness/types.d.ts +46 -0
  44. package/dist/harness/types.js.flow +66 -0
  45. package/dist/index.d.ts +15 -0
  46. package/dist/index.js +185 -127
  47. package/dist/index.js.flow +26 -2
  48. package/dist/mock-requester.d.ts +5 -0
  49. package/dist/mock-requester.js.flow +22 -0
  50. package/dist/respond-with.d.ts +57 -0
  51. package/dist/respond-with.js.flow +91 -0
  52. package/dist/response-impl.d.ts +1 -0
  53. package/dist/response-impl.js.flow +8 -0
  54. package/dist/settle-controller.d.ts +19 -0
  55. package/dist/settle-controller.js.flow +26 -0
  56. package/dist/settle-signal.d.ts +18 -0
  57. package/dist/settle-signal.js.flow +26 -0
  58. package/dist/types.d.ts +25 -0
  59. package/dist/types.js.flow +46 -0
  60. package/package.json +6 -6
  61. package/src/__tests__/{mock-requester.test.js → mock-requester.test.ts} +1 -2
  62. package/src/__tests__/{respond-with.test.js → respond-with.test.ts} +0 -1
  63. package/src/__tests__/response-impl.test.js +1 -1
  64. package/src/__tests__/{settle-controller.test.js → settle-controller.test.ts} +0 -1
  65. package/src/__tests__/{settle-signal.test.js → settle-signal.test.ts} +0 -1
  66. package/src/fetch/__tests__/__snapshots__/{mock-fetch.test.js.snap → mock-fetch.test.ts.snap} +3 -3
  67. package/src/fetch/__tests__/{fetch-request-matches-mock.test.js → fetch-request-matches-mock.test.ts} +5 -6
  68. package/src/fetch/__tests__/{mock-fetch.test.js → mock-fetch.test.ts} +1 -2
  69. package/src/fetch/{fetch-request-matches-mock.js → fetch-request-matches-mock.ts} +3 -2
  70. package/src/fetch/{mock-fetch.js → mock-fetch.ts} +2 -3
  71. package/src/fetch/{types.js → types.ts} +5 -6
  72. package/src/fixtures/__tests__/{fixtures.test.js → fixtures.test.tsx} +6 -4
  73. package/src/fixtures/{fixtures.basic.stories.js → fixtures.basic.stories.tsx} +16 -13
  74. package/src/fixtures/{fixtures.defaultwrapper.stories.js → fixtures.defaultwrapper.stories.tsx} +8 -8
  75. package/src/fixtures/{fixtures.js → fixtures.tsx} +16 -11
  76. package/src/fixtures/{types.js → types.ts} +9 -13
  77. package/src/gql/__tests__/{gql-request-matches-mock.test.js → gql-request-matches-mock.test.ts} +17 -18
  78. package/src/gql/__tests__/{mock-gql-fetch.test.js → mock-gql-fetch.test.tsx} +44 -45
  79. package/src/gql/__tests__/{wb-data-integration.test.js → wb-data-integration.test.tsx} +21 -22
  80. package/src/gql/{gql-request-matches-mock.js → gql-request-matches-mock.ts} +1 -4
  81. package/src/gql/{mock-gql-fetch.js → mock-gql-fetch.ts} +3 -6
  82. package/src/gql/types.ts +33 -0
  83. package/src/harness/__tests__/{hook-harness.test.js → hook-harness.test.ts} +5 -6
  84. package/src/harness/__tests__/{make-hook-harness.test.js → make-hook-harness.test.tsx} +10 -11
  85. package/src/harness/__tests__/{make-test-harness.test.js → make-test-harness.test.tsx} +4 -5
  86. package/src/harness/__tests__/{render-adapters.test.js → render-adapters.test.tsx} +8 -9
  87. package/src/harness/__tests__/{test-harness.test.js → test-harness.test.ts} +5 -6
  88. package/src/harness/__tests__/{types.flowtest.js → types.flowtest.tsx} +24 -27
  89. package/src/harness/adapters/__tests__/{css.test.js → css.test.tsx} +2 -3
  90. package/src/harness/adapters/__tests__/{data.test.js → data.test.tsx} +4 -3
  91. package/src/harness/adapters/__tests__/{portal.test.js → portal.test.tsx} +0 -1
  92. package/src/harness/adapters/__tests__/{router.test.js → router.test.tsx} +75 -56
  93. package/src/harness/adapters/{adapters.js → adapters.ts} +1 -2
  94. package/src/harness/adapters/{css.js → css.tsx} +21 -18
  95. package/src/harness/adapters/{data.js → data.tsx} +7 -5
  96. package/src/harness/adapters/{portal.js → portal.tsx} +3 -4
  97. package/src/harness/adapters/router.tsx +218 -0
  98. package/src/harness/{hook-harness.js → hook-harness.ts} +2 -3
  99. package/src/harness/{make-hook-harness.js → make-hook-harness.ts} +6 -6
  100. package/src/harness/{make-test-harness.js → make-test-harness.tsx} +17 -20
  101. package/src/harness/{render-adapters.js → render-adapters.ts} +4 -4
  102. package/src/harness/{test-harness.js → test-harness.ts} +1 -12
  103. package/src/harness/{types.js → types.ts} +14 -12
  104. package/src/{index.js → index.ts} +0 -2
  105. package/src/{mock-requester.js → mock-requester.ts} +4 -3
  106. package/src/{respond-with.js → respond-with.ts} +42 -37
  107. package/src/{response-impl.js → response-impl.ts} +1 -2
  108. package/src/{settle-controller.js → settle-controller.ts} +9 -7
  109. package/src/{settle-signal.js → settle-signal.ts} +10 -7
  110. package/src/types.ts +40 -0
  111. package/tsconfig.json +11 -0
  112. package/tsconfig.tsbuildinfo +1 -0
  113. package/src/__docs__/_overview_.stories.mdx +0 -18
  114. package/src/__docs__/_overview_fixtures.stories.mdx +0 -18
  115. package/src/__docs__/_overview_mocking.stories.mdx +0 -14
  116. package/src/__docs__/_overview_test_harness.stories.mdx +0 -18
  117. package/src/__docs__/exports.fixtures.stories.mdx +0 -31
  118. package/src/__docs__/exports.harness-adapters.stories.mdx +0 -187
  119. package/src/__docs__/exports.hook-harness.stories.mdx +0 -22
  120. package/src/__docs__/exports.make-hook-harness.stories.mdx +0 -25
  121. package/src/__docs__/exports.make-test-harness.stories.mdx +0 -28
  122. package/src/__docs__/exports.mock-fetch.stories.mdx +0 -40
  123. package/src/__docs__/exports.mock-gql-fetch.stories.mdx +0 -64
  124. package/src/__docs__/exports.respond-with.stories.mdx +0 -84
  125. package/src/__docs__/exports.settle-controller.stories.mdx +0 -32
  126. package/src/__docs__/exports.test-harness.stories.mdx +0 -23
  127. package/src/__docs__/types.fetch-mock-fn.stories.mdx +0 -22
  128. package/src/__docs__/types.fetch-mock-operation.stories.mdx +0 -18
  129. package/src/__docs__/types.fixture-fn.stories.mdx +0 -46
  130. package/src/__docs__/types.fixture-props.stories.mdx +0 -20
  131. package/src/__docs__/types.get-props-options.stories.mdx +0 -52
  132. package/src/__docs__/types.gql-fetch-mock-fn.stories.mdx +0 -27
  133. package/src/__docs__/types.gql-mock-operation.stories.mdx +0 -26
  134. package/src/__docs__/types.mock-response.stories.mdx +0 -22
  135. package/src/__docs__/types.test-harness-adapter.stories.mdx +0 -21
  136. package/src/__docs__/types.test-harness-adapters.stories.mdx +0 -46
  137. package/src/__docs__/types.test-harness-config.stories.mdx +0 -18
  138. package/src/__docs__/types.test-harness-configs.stories.mdx +0 -59
  139. package/src/gql/types.js +0 -34
  140. package/src/harness/adapters/router.js +0 -206
  141. package/src/types.js +0 -39
  142. /package/src/harness/adapters/__tests__/__snapshots__/{router.test.js.snap → router.test.tsx.snap} +0 -0
@@ -1,64 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Mocking / Exports / mockGqlFetch()"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # mockGqlFetch()
13
-
14
- ```ts
15
- mockGqlFetch(): GqlFetchMockFn;
16
- ```
17
-
18
- The `mockGqlFetch` function provides an API to easily mock GraphQL responses for use with the [Wonder Blocks Data GraphQL API](/docs/data-graphql--page). It follows the similar patterns of `jest.fn()` and jest mocks whereby the returned value is both a proxy for the fetch function that is used by [`GqlRouter`](/docs/data-exports-gqlrouter--page) as well as an API for modifying the behavior of that function.
19
-
20
- # API
21
-
22
- Besides being a function that fits the [`GqlFetchFn`](/docs/data-types-gqlfetchfn--page) signature, the return value of `mockGqlFetch()` has an API to customize the behavior of that function. Used in conjunction with the [`RespondWith`](/docs/testing-mocking-exports-respondwith--page) API, this can create a variety of GraphQL responses for testing and stories.
23
-
24
- | Function | Purpose |
25
- | -------- | ------- |
26
- | `mockOperation` | When called, any GraphQL operation that matches the defined mock operation will respond with the given response. |
27
- | `mockOperationOnce` | When called, the first GraphQL operation that matches the defined mock operation will respond with the given response. The mock is only used once. |
28
-
29
- Both of these functions have the same signature:
30
-
31
- ```ts
32
- type GqlMockOperationFn = <
33
- TData: {...},
34
- TVariables: {...},
35
- TContext: GqlContext,
36
- TResponseData: GraphQLJson<TData>,
37
- >(
38
- operation: GqlMockOperation<TData, TVariables, TContext>,
39
- response: MockResponse<TResponseData>,
40
- ) => GqlFetchMockFn;
41
- ```
42
-
43
- # Operation Matching
44
-
45
- The `matchOperation` parameter given to a `mockOperation` or `mockOperationOnce` function is a `GqlMockOperation` defining the actual GraphQL operation to be matched by the mock. The variables and context of the mocked operation change how the mock is matched against requests.
46
-
47
- ```ts
48
- type GqlMockOperation<
49
- TData: {...},
50
- TVariables: {...},
51
- TContext: GqlContext,
52
- > = {|
53
- operation: GqlOperation<TData, TVariables>,
54
- variables?: TVariables,
55
- context?: TContext,
56
- |};
57
- ```
58
-
59
- 1. When `matchOperation.operation` is present but `matchOperation.variables` and `matchOperation.context` are not, the mock will match any request for the
60
- same operation, regardless of variables or context on the request.
61
- 2. When `matchOperation.variables` is present but `matchOperation.context` is not, the mock will match any request for the same operation with matching variables, regardless of context on the request.
62
- 3. When `matchOperation.context` is present but `matchOperation.variables` is not, the mock will match any request for the same operation with matching context, regardless of variables on the request.
63
- 4. When `matchOperation.variables` and `matchOperation.context` are present, the mock will match any request for the same operation with matching variables and context.
64
-
@@ -1,84 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Mocking / Exports / RespondWith"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # RespondWith
13
-
14
- ```ts
15
- interface RespondWith {
16
- /**
17
- * Rejects with an AbortError to simulate an aborted request.
18
- */
19
- abortedRequest: (signal: ?SettleSignal = null) => MockResponse<any>;
20
-
21
- /**
22
- * A non-200 status code with empty text body.
23
- * Equivalent to calling `ResponseWith.text("", statusCode)`.
24
- */
25
- errorStatusCode: (
26
- statusCode: number,
27
- signal: ?SettleSignal = null,
28
- ) => MockResponse<any>;
29
-
30
- /**
31
- * Response with GraphQL data JSON body and status code 200.
32
- */
33
- graphQLData: <TData: {...}>(
34
- data: TData,
35
- signal: ?SettleSignal = null,
36
- ) => MockResponse<GraphQLJson<TData>>;
37
-
38
- /**
39
- * Response that is a GraphQL errors response with status code 200.
40
- */
41
- graphQLErrors: (
42
- errorMessages: $ReadOnlyArray<string>,
43
- signal: ?SettleSignal = null,
44
- ) => MockResponse<any>;
45
-
46
- /**
47
- * Response with JSON body and status code 200.
48
- */
49
- json: <TJson: {...}>(
50
- json: TJson,
51
- signal: ?SettleSignal = null,
52
- ): MockResponse<TJson>;
53
-
54
- /**
55
- * Response body that is valid JSON but not a valid GraphQL response.
56
- */
57
- nonGraphQLBody: (signal: ?SettleSignal = null) => MockResponse<any>;
58
-
59
- /**
60
- * Rejects with the given error.
61
- */
62
- reject: (error: Error, signal: ?SettleSignal = null) => MockResponse<any>;
63
-
64
- /**
65
- * Response with text body and status code.
66
- * Status code defaults to 200.
67
- */
68
- text: <TData = string>(
69
- text: string,
70
- statusCode: number = 200,
71
- signal: ?SettleSignal = null,
72
- ) => MockResponse<TData>;
73
-
74
- /**
75
- * Response with body that will not parse as JSON and status code 200.
76
- */
77
- unparseableBody: (signal: ?SettleSignal = null) => MockResponse<any>;
78
- });
79
- ```
80
-
81
- The `RespondWith` object is a helper for defining mock responses to use with
82
- mock request methods such as [`mockGqlFetch`](/docs/testing-mocking-exports-mockgqlfetch--page).
83
-
84
- Each call takes an optional `signal` that can be used to control when the promise generated from the call resolves. See [`SettleController`](/docs/testing-mocking-exports-settlecontroller--page) for related information.
@@ -1,32 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Mocking / Exports / SettleController"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # SettleController
13
-
14
- ```ts
15
- class SettleController {
16
- /**
17
- * The signal to pass to the `RespondWith` API.
18
- */
19
- get signal(): SettleSignal;
20
-
21
- /**
22
- * Settle the signal and therefore any associated responses.
23
- *
24
- * @throws {Error} if the signal has already been settled.
25
- */
26
- settle(): void;
27
- }
28
- ```
29
-
30
- The `SettleController` is used to control the settling of a signal. This is specifically created to work with the [`RespondWith`](/docs/testing-mocking-exports-respondwith--page) API. The `signal` property it exposes can be passed to `RespondWith` methods and then the `settle` method can be invoked to settle the signal, causing the related responses to either reject or resolve as appropriate.
31
-
32
- This can be useful for tests where the order of operations needs to be controlled in order to verify the expected behaviour of the system under test.
@@ -1,23 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Test Harness / Exports / testHarness()"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # testHarness()
13
-
14
- ```ts
15
- testHarness<-TProps, +Instance = mixed>(
16
- Component: React.AbstractComponent<TProps, Instance>,
17
- configs?: $Shape<TestHarnessConfigs<typeof DefaultAdapters>>,
18
- ): React.AbstractComponent<TProps, Instance>
19
- ```
20
-
21
- This method can be used to create a test harness for a given component. The resultant harnessed component will take the same props as the original component, but will render that component nested inside whatever boilerplate the various harness adapters provide for the given or default configurations.
22
-
23
- This method is created by using [`makeTestHarness`](/docs/testing-test-harness-exports-maketestharness--page) with [`harnessAdapters.DefaultAdapters` and `harnessAdapters.DefaultConfigs`](/docs/testing-test-harness-exports-harnessadapters--page).
@@ -1,22 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Mocking / Types / FetchMockFn"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # FetchMockFn
13
-
14
- ```ts
15
- type FetchMockFn = {|
16
- (input: RequestInfo, init?: RequestOptions): Promise<Response>,
17
- mockOperation: FetchMockOperationFn,
18
- mockOperationOnce: FetchMockOperationFn,
19
- |};
20
- ```
21
-
22
- This type represents the mocking API for `fetch()`. It is the type of the function returned by the [`mockFetch()`](/docs/testing-mocking-exports-mockfetch--page), which is both a drop in replacement for a `fetch()`-like method, but also exposes the mocking API for configuration additional mocks.
@@ -1,18 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Mocking / Types / FetchMockOperation"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # FetchMockOperation
13
-
14
- ```ts
15
- type FetchMockOperation = RegExp | string;
16
- ```
17
-
18
- This defines the operation that a fetch mock will respond to. See [`mockFetch()`](/docs/testing-mocking-exports-mockfetch--page) for more details.
@@ -1,46 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Fixtures / Types / FixtureFn"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # FixtureFn
13
-
14
- ```ts
15
- /**
16
- * A function for defining a fixture.
17
- */
18
- type FixtureFn<TProps: {...}> = (
19
- /**
20
- * The name of the fixture.
21
- */
22
- description: string,
23
-
24
- /**
25
- * The props for the fixture or a function that returns the props.
26
- * The function is injected with an API to facilitate logging.
27
- */
28
- props: FixtureProps<TProps>,
29
-
30
- /**
31
- * An alternative component to render for the fixture.
32
- * Useful if the fixture requires some additional setup for testing the
33
- * component.
34
- */
35
- wrapper?: React.ComponentType<TProps>,
36
- ) => mixed;
37
-
38
- ```
39
-
40
- The [`fixtures`](/docs/testing-fixtures-exports-fixtures--page) method returns a method of this type, specific to the component that was passed into `fixtures`.
41
-
42
- This function takes two or three arguments:
43
-
44
- - `description: string`: A string describing the fixture. This should be used to explain what the fixture is expected to show.
45
- - `props: FixtureProps<TProps>`: The props that the fixture should be rendered with. See [`FixtureProps`](/docs/testing-fixtures-types-fixtureprops--page).
46
- - `wrapper?: React.ComponentType<TProps>`: An optional component that will be rendered for the fixture. This can be used to wrap the fixture in a component that adds additional functionality, such as a test harness (see [`makeTestHarness`](/docs/testing-test-harness-exports-maketestharness--page)).
@@ -1,20 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Fixtures / Types / FixtureProps"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # FixtureProps
13
-
14
- ```ts
15
- type FixtureProps<TProps: {...}> =
16
- | $ReadOnly<TProps>
17
- | ((options: $ReadOnly<GetPropsOptions>) => $ReadOnly<TProps>);
18
- ```
19
-
20
- This type describes how props can be provided to a fixture as either a plain object, or a function that returns a plain object. The function will be called with an API to assist in generating the props (see [`GetPropsOptions`](/docs/testing-fixtures-types-getpropsoptions--page)).
@@ -1,52 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Fixtures / Types / GetPropsOptions"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # GetPropsOptions
13
-
14
- ```ts
15
- type GetPropsOptions = {|
16
- /**
17
- * A function to call that will log output.
18
- */
19
- log: (message: string, ...args: Array<any>) => void,
20
-
21
- /**
22
- * A function to make a handler that will log all arguments with the given
23
- * name or message. Useful for logging events as it avoids the boilerplate
24
- * of the `log` function.
25
- */
26
- logHandler: (name: string) => (...args: Array<any>) => void,
27
- |};
28
- ```
29
-
30
- A fixture can provide a callback that the framework invokes to obtain the props for the fixture component. This callback takes a single argument of type `GetPropsOptions`.
31
-
32
- This has two calls available.
33
-
34
- The `log` callback is for logging output in the context of the fixture. This can be useful for logging information during your fixture. However, in many situations, it is easier to use the `logHandler` callback. The `logHandler` callback takes a single argument of type `string` and returns a function that logs all arguments with the given name or message, allowing easy creation of event handlers that will log that event and its arguments.
35
-
36
- For example:
37
-
38
- ```ts
39
- fixture("My fixture that does logging", ({logHandler}) => ({
40
- onClick: logHandler("onClick"),
41
- }));
42
- ```
43
-
44
- is equivalent to:
45
-
46
- ```ts
47
- fixture("My fixture that does logging", ({log}) => ({
48
- onClick: (...args) => log("onClick", ...args),
49
- }));
50
- ```
51
-
52
-
@@ -1,27 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Mocking / Types / GqlFetchMockFn"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # GqlFetchMockFn
13
-
14
- ```ts
15
- type GqlFetchMockFn = {|
16
- (
17
- operation: GqlOperation<any, any>,
18
- variables: ?{...},
19
- context: GqlContext,
20
- ): Promise<Response>,
21
- mockOperation: GqlMockOperationFn,
22
- mockOperationOnce: GqlMockOperationFn,
23
- |};
24
- ```
25
-
26
- This type represents the mocking API for use with the [Wonder Blocks Data GraphQL API](/docs/data-graphql--page). It is the type of the function returned by the [`mockGqlFetch()`](/docs/testing-mocking-exports-mockgqlfetch--page).
27
-
@@ -1,26 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Mocking / Types / GqlMockOperation<>"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # GqlMockOperation&lt;&gt;
13
-
14
- ```ts
15
- type GqlMockOperation<
16
- TData: {...},
17
- TVariables: {...},
18
- TContext: GqlContext,
19
- > = {|
20
- operation: GqlOperation<TData, TVariables>,
21
- variables?: TVariables,
22
- context?: TContext,
23
- |};
24
- ```
25
-
26
- This defines the operation that a GraphQL mock will respond to. See [`mockGqlFetch`](/docs/testing-mocking-exports-mockgqlfetch--page) for more details.
@@ -1,22 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Mocking / Types / MockResponse<>"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # MockResponse&lt;&gt;
13
-
14
- ```ts
15
- type MockResponse<TJson> = {|
16
- toPromise: () => Promise<Response>,
17
- |};
18
- ```
19
-
20
- This type specifies a mock response. Values of this type are generated by the [`RespondWith`](/docs/testing-mocking-exports-respondwith--page) API. The type parameter is included to allow uses to enforce if they only support `MockResponses` that resolve to a specific JSON pattern.
21
-
22
- The `toPromise` method can be used to generate a new promise from the mocked response definition. Note that `toPromise` will always generate a new promise and any promise created will settle according to any signal passed to the corresponding `RespondWith` API call.
@@ -1,21 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Test Harness / Types / TestHarnessAdapter<>"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # TestHarnessAdapter&lt;&gt;
13
-
14
- ```ts
15
- type TestHarnessAdapter<TConfig> = (
16
- children: React.Node,
17
- config: TConfig,
18
- ) => React.Element<any>;
19
- ```
20
-
21
- This type represents the signature of a an adapter function for use with the test harness framework methods, [`makeTestHarness()`](/docs/testing-test-harness-exports-maketestharness--page) and [`makeHookHarness()`](/docs/testing-test-harness-exports-makehookharness--page).
@@ -1,46 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Test Harness / Types / TestHarnessAdapters"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # TestHarnessAdapters
13
-
14
- ```ts
15
- type TestHarnessAdapters = {|
16
- [adapterID: string]: TestHarnessAdapter<any>,
17
- |};
18
- ```
19
-
20
- Defines a generic collection of test harness adapters.
21
-
22
- Only use `TestHarnessAdapters` in input locations to verify a set of adapters conforms to that type, but avoid using it in output locations as it can erase useful type information.
23
-
24
- For example, the [`harnessAdapters.DefaultAdapters`](/docs/testing-test-harness-exports-harnessadapters--page) type is specific to the adapters it contains.
25
-
26
- ```ts
27
- const DefaultAdapters = {
28
- css: css.adapter,
29
- data: data.adapter,
30
- portal: portal.adapter,
31
- router: router.adapter,
32
- };
33
- ```
34
-
35
- `DefaultAdapters` is not strongly typed to `TestHarnessAdapters`. Instead, its type is:
36
-
37
- ```ts
38
- type DefaultAdaptersType = {|
39
- css: typeof css.adapter,
40
- data: typeof data.adapter,
41
- portal: typeof portal.adapter,
42
- router: typeof router.adapter,
43
- |};
44
- ```
45
-
46
- It conforms to the `TestHarnessAdapters` type because each key is a string and the value of each property is a variation of `TestHarnessAdapter<TConfig>` with a different type for `TConfig` in each case, but it is not equivalent to the `TestHarnessAdapters` type where each key is a string and each value is exactly `TestHarnessAdapter<any>`.
@@ -1,18 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Test Harness / Types / TestHarnessConfig<>"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # TestHarnessConfig&lt;&gt;
13
-
14
- ```ts
15
- type TestHarnessConfig<TAdapter>;
16
- ```
17
-
18
- When given an adapter type conforming to [`TestHarnessAdapter`](/docs/testing-test-harness-types-testharnessadapter--page), this type will represent that adapter type's configuration type.
@@ -1,59 +0,0 @@
1
- import {Meta} from "@storybook/addon-docs";
2
-
3
- <Meta
4
- title="Testing / Test Harness / Types / TestHarnessConfigs<>"
5
- parameters={{
6
- chromatic: {
7
- disableSnapshot: true,
8
- },
9
- }}
10
- />
11
-
12
- # TestHarnessConfigs&lt;&gt;
13
-
14
- ```ts
15
- type TestHarnessConfigs<TAdapters: TestHarnessAdapters>;
16
- ```
17
-
18
- When given the type of a set of adapters conforming to [`TestHarnessAdapters`](/docs/testing-test-harness-types-testharnessadapters--page), this type will represent a set of configurations for those adapters.
19
-
20
- It is important to note here that if the `TAdapters` type passed in is the actual `TestHarnessAdapters` type, then the resulting configuration type will have each adapter's config being set to `any`. Instead of using the `TestHarnessAdapters` type directly, the passed object should not be typed as that, but should merely conform to that type.
21
-
22
- For example, the [`harnessAdapters.DefaultAdapters`](/docs/testing-test-harness-exports-harnessadapters--page) type is specific to the adapters it contains.
23
-
24
- ```ts
25
- const DefaultAdapters = {
26
- css: css.adapter,
27
- data: data.adapter,
28
- portal: portal.adapter,
29
- router: router.adapter,
30
- };
31
- ```
32
-
33
- `DefaultAdapters` is not strongly typed to `TestHarnessAdapters`. Instead, its type is:
34
-
35
- ```ts
36
- type DefaultAdaptersType = {|
37
- css: typeof css.adapter,
38
- data: typeof data.adapter,
39
- portal: typeof portal.adapter,
40
- router: typeof router.adapter,
41
- |};
42
- ```
43
-
44
- It conforms to the `TestHarnessAdapters` type, but it is not equivalent to the `TestHarnessAdapters` type. This is important when we consider the companion export, [`harnessAdapters.DefaultConfigs`](/docs/testing-test-harness-exports-harnessadapters--page).
45
-
46
- ```ts
47
- const DefaultConfigs: TestHarnessConfigs<typeof DefaultAdapters> = {
48
- css: css.defaultConfig,
49
- data: data.defaultConfig,
50
- portal: portal.defaultConfig,
51
- router: router.defaultConfig,
52
- };
53
- ```
54
-
55
- `DefaultConfigs` is typed using `TestHarnessConfigs<typeof DefaultAdapters>`. Because `DefaultAdapters` is strongly typed specifically to each adapter it contains, the type that `TestHarnessConfigs<>` creates ensures that there is one configuration per adapter key, and that the configuration type for each adapter key is correct for the corresponding adapter.
56
-
57
- If we had typed `DefaultAdapters` as `TestHarnessAdapters`, then although we would still enforce one configuration per adapter key, we would allow `any` type to provide that configuration, which does not give us any real type safety.
58
-
59
- So, to summarize, use `TestHarnessAdapters` in input locations to verify a set of adapters conforms to that type, but avoid using it in output locations as it can erase useful type information.
package/src/gql/types.js DELETED
@@ -1,34 +0,0 @@
1
- //@flow
2
- import type {GqlOperation, GqlContext} from "@khanacademy/wonder-blocks-data";
3
- import type {GraphQLJson} from "../types";
4
- import type {MockResponse} from "../respond-with";
5
-
6
- export type GqlMockOperation<
7
- TData: {...},
8
- TVariables: {...},
9
- TContext: GqlContext,
10
- > = {|
11
- operation: GqlOperation<TData, TVariables>,
12
- variables?: TVariables,
13
- context?: TContext,
14
- |};
15
-
16
- type GqlMockOperationFn = <
17
- TData: {...},
18
- TVariables: {...},
19
- TContext: GqlContext,
20
- TResponseData: GraphQLJson<TData>,
21
- >(
22
- operation: GqlMockOperation<TData, TVariables, TContext>,
23
- response: MockResponse<TResponseData>,
24
- ) => GqlFetchMockFn;
25
-
26
- export type GqlFetchMockFn = {|
27
- (
28
- operation: GqlOperation<any, any>,
29
- variables: ?{...},
30
- context: GqlContext,
31
- ): Promise<Response>,
32
- mockOperation: GqlMockOperationFn,
33
- mockOperationOnce: GqlMockOperationFn,
34
- |};