@codecademy/gamut-tests 7.1.1-alpha.b40fc8.0 → 7.1.1-alpha.c19f83.0

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/dist/index.d.ts CHANGED
@@ -1,7 +1,22 @@
1
- import { setupRtl as setupRtlBase } from 'component-test-setup';
1
+ import { FullProps, RemainingPropsAndTestOverrides, RenderRtl, SetupComponentType } from 'component-test-setup';
2
2
  import * as React from 'react';
3
3
  export declare const MockGamutProvider: React.FC<{
4
4
  children?: React.ReactNode;
5
5
  useLogicalProperties?: boolean;
6
6
  }>;
7
- export declare const setupRtl: typeof setupRtlBase;
7
+ type StripDataAttrs<T> = {
8
+ [K in keyof T as K extends `data-${string}` ? never : K]: T[K];
9
+ };
10
+ type RequiredKeys<T> = {
11
+ [K in keyof T]-?: Record<string, unknown> extends {
12
+ [P in K]: T[K];
13
+ } ? never : K;
14
+ }[keyof T];
15
+ type TestProps<Component extends SetupComponentType, BaseProps extends Partial<FullProps<Component>>> = RequiredKeys<StripDataAttrs<Omit<FullProps<Component>, keyof BaseProps>>> extends never ? [RemainingPropsAndTestOverrides<Component, BaseProps>?] : [RemainingPropsAndTestOverrides<Component, BaseProps>];
16
+ export type GamutRenderRtlReturn<Component extends SetupComponentType, BaseProps extends Partial<FullProps<Component>>> = ReturnType<RenderRtl<Component, BaseProps>>;
17
+ export type GamutRenderRtl<Component extends SetupComponentType, BaseProps extends Partial<FullProps<Component>>> = {
18
+ (...testProps: TestProps<Component, BaseProps>): GamutRenderRtlReturn<Component, BaseProps>;
19
+ options: (options: Parameters<RenderRtl<Component, BaseProps>['options']>[0]) => GamutRenderRtl<Component, BaseProps>;
20
+ };
21
+ export declare const setupRtl: <Component extends SetupComponentType, BaseProps extends Partial<FullProps<Component>> = {}>(Component: Component, baseProps?: BaseProps) => GamutRenderRtl<Component, BaseProps>;
22
+ export {};
package/dist/index.js CHANGED
@@ -26,6 +26,24 @@ function withMockGamutProvider(WrappedComponent) {
26
26
  return WithBoundaryComponent;
27
27
  }
28
28
 
29
+ /*
30
+ * component-test-setup decides whether `renderView`'s argument is required by
31
+ * asking, for each key of the props type, whether an arbitrary object would
32
+ * satisfy it. A `data-*` index signature (`DataAttributes` in
33
+ * @codecademy/gamut) answers no, since `unknown` isn't assignable to its value
34
+ * type, so the key gets treated as required and `renderView()` with no
35
+ * arguments stops compiling. Index signatures are never genuinely required, so
36
+ * drop them before that decision is made. Types only; no runtime effect.
37
+ */
38
+
39
+ // mirrors component-test-setup's internal RequiredKeys, which it doesn't export
40
+
41
+ /*
42
+ * component-test-setup doesn't export the type of what a render returns, so
43
+ * alias it here. Without an exported name, anything that re-exports a
44
+ * `renderView` fails declaration emit with TS4023.
45
+ */
46
+
29
47
  // overArgs isn't fully typed yet for lack of curried generics, so we have to cast it...
30
48
 
31
49
  export const setupRtl = overArgs(setupRtlBase, withMockGamutProvider);
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@codecademy/gamut-tests",
3
3
  "description": "Shared component test setup for Gamut applications",
4
- "version": "7.1.1-alpha.b40fc8.0",
4
+ "version": "7.1.1-alpha.c19f83.0",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
6
  "dependencies": {
7
- "@codecademy/gamut-styles": "21.2.1-alpha.b40fc8.0",
7
+ "@codecademy/gamut-styles": "21.2.1-alpha.c19f83.0",
8
8
  "component-test-setup": "*",
9
9
  "lodash": "^4.17.23"
10
10
  },