Skip to content

Commit

Permalink
Merge pull request #17382 from storybookjs/fix/do-not-throw-missing-c…
Browse files Browse the repository at this point in the history
…hannel-error

Core: Mock channel if not present
  • Loading branch information
shilman committed Feb 2, 2022
2 parents fed495a + d007158 commit 6e74df5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/addons/src/index.ts
Expand Up @@ -5,6 +5,7 @@ import { API } from '@storybook/api';
import { RenderData as RouterData } from '@storybook/router';
import { logger } from '@storybook/client-logger';
import { ThemeVars } from '@storybook/theming';
import { mockChannel } from './storybook-channel-mock';
import { types, Types } from './types';

export { Channel };
Expand Down Expand Up @@ -70,11 +71,9 @@ export class AddonStore {
private resolve: any;

getChannel = (): Channel => {
// this.channel should get overwritten by setChannel. If it wasn't called (e.g. in non-browser environment), throw.
// this.channel should get overwritten by setChannel. If it wasn't called (e.g. in non-browser environment), set a mock instead.
if (!this.channel) {
throw new Error(
'Accessing non-existent addons channel, see https://storybook.js.org/basics/faq/#why-is-there-no-addons-channel'
);
this.setChannel(mockChannel());
}

return this.channel;
Expand Down

0 comments on commit 6e74df5

Please sign in to comment.