Skip to content

Commit e811ddc

Browse files
Ashley Blurtonwyattdanger
authored andcommitted
Correctly detect and handle undefined/null in action calls (storybookjs#133)
1 parent d62c9db commit e811ddc

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

dist/client/client_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ var ClientApi = function () {
9090
// Remove events from the args. Otherwise, it creates a huge JSON string.
9191

9292
args = args.map(function (arg) {
93-
if (typeof arg.preventDefault === 'function') {
93+
if (arg && typeof arg.preventDefault === 'function') {
9494
return '[SyntheticEvent]';
9595
}
9696
return arg;

src/client/__tests__/client_api.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,25 @@ describe('client.ClientApi', () => {
125125
}]);
126126
});
127127

128+
it('should accept null and undefined values', () => {
129+
const api = getClientApi();
130+
api._syncedStore.getData = () => ({ actions: [] });
131+
api._syncedStore.setData = sinon.stub();
132+
133+
const cb = api.action('hello');
134+
cb(null, void 0);
135+
136+
const args = api._syncedStore.setData.args[0];
137+
const actions = clearActionId(args[0].actions);
138+
expect(actions).to.be.deep.equal([{
139+
data: {
140+
name: 'hello',
141+
args: [null, void 0],
142+
},
143+
count: 1,
144+
}]);
145+
});
146+
128147
it('should only keep the latest 10 actions in the syncedStore', () => {
129148
const api = getClientApi();
130149
api._syncedStore.getData = () => ({

src/client/client_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class ClientApi {
4747

4848
// Remove events from the args. Otherwise, it creates a huge JSON string.
4949
args = args.map(arg => {
50-
if (typeof arg.preventDefault === 'function') {
50+
if (arg && typeof arg.preventDefault === 'function') {
5151
return '[SyntheticEvent]';
5252
}
5353
return arg;

0 commit comments

Comments
 (0)