@khanacademy/wonder-blocks-testing 7.0.1 → 7.0.4

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,25 @@
1
1
  # @khanacademy/wonder-blocks-testing
2
2
 
3
+ ## 7.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [08238b89]
8
+ - @khanacademy/wonder-blocks-data@8.0.5
9
+
10
+ ## 7.0.3
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [dc2e00f4]
15
+ - @khanacademy/wonder-blocks-data@8.0.4
16
+
17
+ ## 7.0.2
18
+
19
+ ### Patch Changes
20
+
21
+ - aa7993a8: Make sure wrapper component is used when provided
22
+
3
23
  ## 7.0.1
4
24
 
5
25
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -17,12 +17,13 @@ const fixtures = Component => {
17
17
 
18
18
  const getProps = options => typeof props === "function" ? props(options) : props;
19
19
 
20
- let Template = templateMap.get(Component);
20
+ const RealComponent = wrapper || Component;
21
+ let Template = templateMap.get(RealComponent);
21
22
 
22
23
  if (Template == null) {
23
- Template = args => React.createElement(Component, args);
24
+ Template = args => React.createElement(RealComponent, args);
24
25
 
25
- templateMap.set(Component, Template);
26
+ templateMap.set(RealComponent, Template);
26
27
  }
27
28
 
28
29
  const story = Template.bind({});
package/dist/index.js CHANGED
@@ -719,20 +719,21 @@ const fixtures = Component => {
719
719
  const makeStory = (description, props, wrapper = null) => {
720
720
  const storyName = `${storyNumber++} ${description}`;
721
721
 
722
- const getProps = options => typeof props === "function" ? props(options) : props; // We create a “template” of how args map to rendering
722
+ const getProps = options => typeof props === "function" ? props(options) : props;
723
+
724
+ const RealComponent = wrapper || Component; // We create a “template” of how args map to rendering
723
725
  // for each type of component as the component here could
724
726
  // be the component under test, or wrapped in a wrapper
725
727
  // component. We don't use decorators for the wrapper
726
728
  // because we may not be in a storybook context and it
727
729
  // keeps the framework API simpler this way.
728
730
 
729
-
730
- let Template = templateMap.get(Component);
731
+ let Template = templateMap.get(RealComponent);
731
732
 
732
733
  if (Template == null) {
733
- Template = args => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](Component, args);
734
+ Template = args => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](RealComponent, args);
734
735
 
735
- templateMap.set(Component, Template);
736
+ templateMap.set(RealComponent, Template);
736
737
  } // Each story that shares that component then reuses that
737
738
  // template.
738
739
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-testing",
3
- "version": "7.0.1",
3
+ "version": "7.0.4",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@babel/runtime": "^7.18.6",
17
- "@khanacademy/wonder-blocks-data": "^8.0.3"
17
+ "@khanacademy/wonder-blocks-data": "^8.0.5"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@khanacademy/wonder-stuff-core": "^0.1.2",
@@ -128,5 +128,23 @@ describe("fixtures", () => {
128
128
  screen.getByText('I rendered {"aProp":"aValue"}'),
129
129
  ).toBeInTheDocument();
130
130
  });
131
+
132
+ it("should render the wrapper", () => {
133
+ // Arrange
134
+ const fixture = fixtures(
135
+ (props) => `I rendered ${JSON.stringify(props)}`,
136
+ );
137
+ const Fixture: any = fixture(
138
+ "A simple story",
139
+ {},
140
+ () => "I am a wrapper",
141
+ );
142
+
143
+ // Act
144
+ render(<Fixture aProp="aValue" />);
145
+
146
+ // Assert
147
+ expect(screen.getByText("I am a wrapper")).toBeInTheDocument();
148
+ });
131
149
  });
132
150
  });
@@ -44,16 +44,18 @@ export const fixtures = <
44
44
  const getProps = (options) =>
45
45
  typeof props === "function" ? props(options) : props;
46
46
 
47
+ const RealComponent = wrapper || Component;
48
+
47
49
  // We create a “template” of how args map to rendering
48
50
  // for each type of component as the component here could
49
51
  // be the component under test, or wrapped in a wrapper
50
52
  // component. We don't use decorators for the wrapper
51
53
  // because we may not be in a storybook context and it
52
54
  // keeps the framework API simpler this way.
53
- let Template = templateMap.get((Component: any));
55
+ let Template = templateMap.get((RealComponent: any));
54
56
  if (Template == null) {
55
- Template = (args) => <Component {...args} />;
56
- templateMap.set((Component: any), Template);
57
+ Template = (args) => <RealComponent {...args} />;
58
+ templateMap.set((RealComponent: any), Template);
57
59
  }
58
60
 
59
61
  // Each story that shares that component then reuses that