@khanacademy/wonder-blocks-testing 5.0.2 → 6.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @khanacademy/wonder-blocks-testing
2
2
 
3
+ ## 6.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - af459222: Improve typing for fixtures call
8
+
3
9
  ## 5.0.2
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-testing",
3
- "version": "5.0.2",
3
+ "version": "6.0.0",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -48,7 +48,7 @@ describe("#fixtures", () => {
48
48
  });
49
49
 
50
50
  // Act
51
- fixtures(
51
+ fixtures<any, _>(
52
52
  {
53
53
  title: "TITLE",
54
54
  description: "DESCRIPTION",
@@ -81,7 +81,7 @@ describe("#fixtures", () => {
81
81
  component.displayName = "DISPLAYNAME";
82
82
 
83
83
  // Act
84
- fixtures(
84
+ fixtures<any, _>(
85
85
  {
86
86
  component,
87
87
  },
@@ -157,7 +157,7 @@ describe("#fixtures", () => {
157
157
  const fn = jest.fn();
158
158
 
159
159
  // Act
160
- fixtures(
160
+ fixtures<any, _>(
161
161
  {
162
162
  title: "GROUP_TITLE",
163
163
  description: "GROUP_DESCRIPTION",
@@ -196,7 +196,7 @@ describe("#fixtures", () => {
196
196
  };
197
197
 
198
198
  // Act
199
- fixtures(
199
+ fixtures<any, _>(
200
200
  {
201
201
  component: () => "COMPONENT",
202
202
  additionalAdapterOptions: {
@@ -241,7 +241,7 @@ describe("#fixtures", () => {
241
241
  };
242
242
 
243
243
  // Act
244
- fixtures(
244
+ fixtures<any, _>(
245
245
  {
246
246
  component: () => "COMPONENT",
247
247
  additionalAdapterOptions: {
@@ -273,7 +273,7 @@ describe("#fixtures", () => {
273
273
  });
274
274
 
275
275
  // Act
276
- const result = fixtures(
276
+ const result = fixtures<any, _>(
277
277
  {
278
278
  component: () => "COMPONENT",
279
279
  },
@@ -301,7 +301,7 @@ describe("#fixtures", () => {
301
301
  const component = () => "COMPONENT";
302
302
 
303
303
  // Act
304
- fixtures(
304
+ fixtures<any, _>(
305
305
  {
306
306
  title: "GROUP_TITLE",
307
307
  description: "GROUP_DESCRIPTION",
@@ -367,7 +367,7 @@ describe("#fixtures", () => {
367
367
  const wrapper = () => "WRAPPER";
368
368
 
369
369
  // Act
370
- fixtures(
370
+ fixtures<any, _>(
371
371
  {
372
372
  title: "GROUP_TITLE",
373
373
  description: "GROUP_DESCRIPTION",
@@ -407,7 +407,7 @@ describe("#fixtures", () => {
407
407
  const defaultWrapper = () => "DEFAULT_WRAPPER";
408
408
 
409
409
  // Act
410
- fixtures(
410
+ fixtures<any, _>(
411
411
  {
412
412
  title: "GROUP_TITLE",
413
413
  description: "GROUP_DESCRIPTION",
@@ -443,7 +443,7 @@ describe("#fixtures", () => {
443
443
  });
444
444
 
445
445
  // Act
446
- fixtures(
446
+ fixtures<any, _>(
447
447
  {
448
448
  component: () => "COMPONENT",
449
449
  },
@@ -475,7 +475,7 @@ describe("#fixtures", () => {
475
475
  const props = jest.fn().mockReturnValue({these: "areProps"});
476
476
 
477
477
  // Act
478
- fixtures(
478
+ fixtures<any, _>(
479
479
  {
480
480
  component: () => "COMPONENT",
481
481
  },
@@ -507,7 +507,7 @@ describe("#fixtures", () => {
507
507
  const props = jest.fn().mockReturnValue({these: "areProps"});
508
508
 
509
509
  // Act
510
- fixtures(
510
+ fixtures<any, _>(
511
511
  {
512
512
  component: () => "COMPONENT",
513
513
  },
@@ -12,7 +12,12 @@ setupFixtures({
12
12
  adapter: adapters.storybook(),
13
13
  });
14
14
 
15
- const MyComponent = (props) =>
15
+ type Props = {|
16
+ propA: string,
17
+ propB?: string,
18
+ |};
19
+
20
+ const MyComponent = (props: Props) =>
16
21
  `I am a component. Here are my props: ${JSON.stringify(props, null, 2)}`;
17
22
 
18
23
  const Wrapper = (props) => (
@@ -24,15 +29,15 @@ const Wrapper = (props) => (
24
29
  );
25
30
 
26
31
  const stories: Array<mixed> = Object.values(
27
- fixtures(
32
+ fixtures<typeof MyComponent, _>(
28
33
  {
29
34
  component: MyComponent,
30
35
  title: "Testing / Fixtures / Basic",
31
36
  },
32
37
  (fixture) => {
33
38
  fixture("This is a fixture with some regular props", {
34
- see: "this is a prop",
35
- and: "this is another",
39
+ propA: "this is a prop",
40
+ propB: "this is another",
36
41
  });
37
42
 
38
43
  fixture(
@@ -45,7 +50,7 @@ const stories: Array<mixed> = Object.values(
45
50
  },
46
51
  );
47
52
  return {
48
- this: "prop was made from a function",
53
+ propA: "prop was made from a function",
49
54
  };
50
55
  },
51
56
  );
@@ -53,8 +58,8 @@ const stories: Array<mixed> = Object.values(
53
58
  fixture(
54
59
  "This fixture uses a custom wrapper",
55
60
  {
56
- just: "some props again",
57
- like: "this one",
61
+ propA: "some props again",
62
+ propB: "this one",
58
63
  },
59
64
  Wrapper,
60
65
  );
@@ -31,7 +31,7 @@ const DefaultWrapper = (props) => (
31
31
  );
32
32
 
33
33
  const stories: Array<mixed> = Object.values(
34
- fixtures(
34
+ fixtures<typeof MyComponent, _>(
35
35
  {
36
36
  component: MyComponent,
37
37
  title: "Testing / Fixtures / DefaultWrapper",
@@ -9,11 +9,14 @@ type FixtureProps<TProps: {...}> =
9
9
  | $ReadOnly<TProps>
10
10
  | ((options: $ReadOnly<GetPropsOptions>) => $ReadOnly<TProps>);
11
11
 
12
- const normalizeOptions = <TProps: {...}>(
12
+ const normalizeOptions = <
13
+ TComponent: React.ComponentType<any>,
14
+ TProps: React.ElementConfig<TComponent>,
15
+ >(
13
16
  componentOrOptions:
14
- | React.ComponentType<TProps>
15
- | $ReadOnly<FixturesOptions<TProps>>,
16
- ): $ReadOnly<FixturesOptions<TProps>> => {
17
+ | TComponent
18
+ | $ReadOnly<FixturesOptions<TComponent, TProps>>,
19
+ ): $ReadOnly<FixturesOptions<TComponent, TProps>> => {
17
20
  // To differentiate between a React component and a FixturesOptions object,
18
21
  // we have to do some type checking.
19
22
  //
@@ -66,10 +69,13 @@ const normalizeOptions = <TProps: {...}>(
66
69
  * storybook, the popular framework, uses both default and named exports for
67
70
  * its interface.
68
71
  */
69
- export const fixtures = <TProps: {...}>(
72
+ export const fixtures = <
73
+ TComponent: React.ComponentType<any>,
74
+ TProps: React.ElementConfig<TComponent>,
75
+ >(
70
76
  componentOrOptions:
71
- | React.ComponentType<TProps>
72
- | $ReadOnly<FixturesOptions<TProps>>,
77
+ | TComponent
78
+ | $ReadOnly<FixturesOptions<TComponent, TProps>>,
73
79
  fn: (
74
80
  fixture: (
75
81
  description: string,
@@ -86,7 +92,7 @@ export const fixtures = <TProps: {...}>(
86
92
  description: groupDescription,
87
93
  defaultWrapper,
88
94
  additionalAdapterOptions,
89
- } = normalizeOptions(componentOrOptions);
95
+ } = normalizeOptions<TComponent, TProps>(componentOrOptions);
90
96
 
91
97
  // 1. Create a new adapter group.
92
98
  const group = adapter.declareGroup<TProps>({
@@ -23,11 +23,14 @@ export type FixturesAdapterOptions = {|
23
23
  /**
24
24
  * Options to describe a collection of fixtures.
25
25
  */
26
- export type FixturesOptions<TProps: {...}> = {|
26
+ export type FixturesOptions<
27
+ TComponent: React.ComponentType<any>,
28
+ TProps: React.ElementConfig<TComponent>,
29
+ > = {|
27
30
  /**
28
31
  * The component being tested by the fixtures.
29
32
  */
30
- component: React.ComponentType<TProps>,
33
+ component: TComponent,
31
34
 
32
35
  /**
33
36
  * Optional title of the fixture collection.