-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
when testing with storyshots, args with a null value entry break the story loading chain #12540
Comments
The same issue for |
I've been bashing my head against the keyboard for more than a week and just found out that the null and undefined will break the whole jest storyshot generation. After removing the null arg, it started working. |
I’m not sure if this is clear enough from the above:
To me the fact that this is all happening while the test suite still passes is much more problematic than those few stories not working as expected. The error is: Cannot read property 'defaultValue' of undefined
It’s raised here, as part of the array destructuring, because the expected storybook/lib/client-api/src/story_store.ts Lines 413 to 415 in 748710c
It gets swallowed by the storybook/lib/client-api/src/config_api.ts Lines 18 to 20 in 748710c
As far as I can see, this Without understanding it all, storybook/lib/client-api/src/story_store.ts Lines 412 to 418 in 748710c
const passedArgs: Args = combinedParameters.args;
const defaultArgs: Args = Object.entries(
- argTypes as Record<string, { defaultValue: any }>
-).reduce((acc, [arg, { defaultValue }]) => {
- if (defaultValue) acc[arg] = defaultValue;
+ argTypes as Record<string, { defaultValue: any } | undefined>
+).reduce((acc, [arg, argType]) => {
+ if (argType && typeof argType.defaultValue !== 'undefined') acc[arg] = defaultValue;
return acc;
}, {} as Args); I haven’t checked why the error is silently swallowed and doesn’t just break the tests. Minimal repro if it helps – CRA + default Storybook setup + Storyshots, and a story with |
Thanks so much @thibaudcolas -- I'll try out your fix and see what it does. I'm very interested in fixing things on the args side of things, don't have the bandwidth to fix the storyshots side, so PRs welcome on better error handling there. |
Related: #12729 |
I was bashing my head against the desk when I found this issue after four hours of experimenting. It'd be awesome if this gets fixed soon as it has been reported in September. The changes in #12809 do partially fix the execution of tests via storyshots and I am currently monkey-patching it after installing the dependency. I had to check for undefined and null. Here is the patch based on 6.1.0-beta.0 I am using with diff --git a/node_modules/@storybook/client-api/dist/story_store.js b/node_modules/@storybook/client-api/dist/story_store.js
index 097134a..9ff3fba 100644
--- a/node_modules/@storybook/client-api/dist/story_store.js
+++ b/node_modules/@storybook/client-api/dist/story_store.js
@@ -404,10 +404,9 @@ var StoryStore = /*#__PURE__*/function () {
globalTypes = _this$_globalMetadata3 === void 0 ? {} : _this$_globalMetadata3;
var defaultGlobals = Object.entries(globalTypes).reduce(function (acc, _ref8) {
var _ref9 = _slicedToArray(_ref8, 2),
- arg = _ref9[0],
- defaultValue = _ref9[1].defaultValue;
+ arg = _ref9[0];
- if (defaultValue) acc[arg] = defaultValue;
+ if (_ref9[1] && typeof _ref9[1].defaultValue !== 'undefined' && _ref9[1].defaultValue !== null) acc[arg] = _ref9[1].defaultValue;
return acc;
}, {});
var allowedGlobals = new Set([].concat(_toConsumableArray(Object.keys(initialGlobals)), _toConsumableArray(Object.keys(globalTypes)))); // To deal with HMR & persistence, we consider the previous value of global args, and:
@@ -729,10 +728,9 @@ var StoryStore = /*#__PURE__*/function () {
var passedArgs = Object.assign({}, this._kinds[kind].parameters.args, storyParameters.args);
var defaultArgs = Object.entries(argTypes).reduce(function (acc, _ref17) {
var _ref18 = _slicedToArray(_ref17, 2),
- arg = _ref18[0],
- defaultValue = _ref18[1].defaultValue;
+ arg = _ref18[0];
- if (defaultValue) acc[arg] = defaultValue;
+ if (_ref18[1] && typeof _ref18[1].defaultValue !== 'undefined' && _ref18[1].defaultValue !== null) acc[arg] = _ref18[1].defaultValue;
return acc;
}, {});
var initialArgs = Object.assign({}, defaultArgs, passedArgs); And this is the patch file for version 6.0.28: diff --git a/node_modules/@storybook/client-api/dist/story_store.js b/node_modules/@storybook/client-api/dist/story_store.js
index 9b0a8ba..6c8cf7c 100644
--- a/node_modules/@storybook/client-api/dist/story_store.js
+++ b/node_modules/@storybook/client-api/dist/story_store.js
@@ -383,10 +383,9 @@ var StoryStore = /*#__PURE__*/function () {
globalTypes = _this$_globalMetadata3 === void 0 ? {} : _this$_globalMetadata3;
var defaultGlobals = Object.entries(globalTypes).reduce(function (acc, _ref8) {
var _ref9 = _slicedToArray(_ref8, 2),
- arg = _ref9[0],
- defaultValue = _ref9[1].defaultValue;
+ arg = _ref9[0];
- if (defaultValue) acc[arg] = defaultValue;
+ if (_ref9[1] && typeof _ref9[1].defaultValue !== 'undefined' && _ref9[1].defaultValue !== null) acc[arg] = _ref9[1].defaultValue;
return acc;
}, {});
var allowedGlobals = new Set([].concat(_toConsumableArray(Object.keys(initialGlobals)), _toConsumableArray(Object.keys(globalTypes)))); // To deal with HMR & persistence, we consider the previous value of global args, and:
@@ -640,10 +639,9 @@ var StoryStore = /*#__PURE__*/function () {
var passedArgs = combinedParameters.args;
var defaultArgs = Object.entries(argTypes).reduce(function (acc, _ref16) {
var _ref17 = _slicedToArray(_ref16, 2),
- arg = _ref17[0],
- defaultValue = _ref17[1].defaultValue;
+ arg = _ref17[0];
- if (defaultValue) acc[arg] = defaultValue;
+ if (_ref17[1] && typeof _ref17[1].defaultValue !== 'undefined' && _ref17[1].defaultValue !== null) acc[arg] = _ref17[1].defaultValue;
return acc;
}, {});
var initialArgs = Object.assign(Object.assign({}, defaultArgs), passedArgs); |
@ChristianIvicevic it’s not clear to me why you checked for |
@thibaudcolas Let me preface this by saying I don't know the codebase of Storybook at all so this was merely trial and error for me and hence I don't know any relations and intricacies here. I noticed before checking for Furthermore due to my personal code style I never work with |
I just tested the latest beta of v6.1 and my patch is no longer necessary. Storyshots have been fixed for all occurences of |
Hooray! Closing. |
Describe the bug
using
@storybook/react v6.0.21
When running image snapshot tests, storybook fails to load a story with a args parameter entry with a null value, even though the component's type for that prop takes null.
The story renders properly in the storybook UI though
To Reproduce
Steps to reproduce the behavior:
ProgressBar
component from kendo uiMind you that ProgressBar declares a
number|null
value propExpected behavior
story to be picked up and test run.
System:
Environment Info:
The text was updated successfully, but these errors were encountered: