Skip to content

Commit

Permalink
fix(addons): webcomponents excludeDecorators
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Jul 10, 2021
1 parent 2c47a6e commit 9a5dccd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 27 additions & 0 deletions addons/docs/src/frameworks/web-components/sourceDecorator.test.ts
@@ -1,4 +1,5 @@
import { html } from 'lit-html';
import { styleMap } from 'lit-html/directives/style-map';
import { addons, StoryContext } from '@storybook/addons';
import { sourceDecorator } from './sourceDecorator';
import { SNIPPET_RENDERED } from '../../shared';
Expand Down Expand Up @@ -49,6 +50,32 @@ describe('sourceDecorator', () => {
expect(mockChannel.emit).not.toHaveBeenCalled();
});

it('should use the originalStoryFn if excludeDecorators is set', () => {
const storyFn = (args: any) => html`<div>args story</div>`;
const decoratedStoryFn = (args: any) => html`
<div style=${styleMap({ padding: `${25}px`, border: '3px solid red' })}>${storyFn(args)}</div>
`;
const context = makeContext(
'args',
{
__isArgsStory: true,
docs: {
source: {
excludeDecorators: true,
},
},
},
{},
{ originalStoryFn: storyFn }
);
sourceDecorator(decoratedStoryFn, context);
expect(mockChannel.emit).toHaveBeenCalledWith(
SNIPPET_RENDERED,
'lit-test--args',
'<div>args story</div>'
);
});

it('allows the snippet output to be modified by transformSource', () => {
const storyFn = (args: any) => html`<div>args story</div>`;
const transformSource = (dom: string) => `<p>${dom}</p>`;
Expand Down
4 changes: 3 additions & 1 deletion addons/docs/src/frameworks/web-components/sourceDecorator.ts
Expand Up @@ -24,7 +24,9 @@ function applyTransformSource(source: string, context: StoryContext): string {
}

export function sourceDecorator(storyFn: StoryFn, context: StoryContext) {
const story = storyFn();
const story = context?.parameters.docs?.source?.excludeDecorators
? context.originalStoryFn(context.args)
: storyFn();

if (!skipSourceRender(context)) {
const container = window.document.createElement('div');
Expand Down

0 comments on commit 9a5dccd

Please sign in to comment.