Skip to content

Commit

Permalink
Add tests for rerendering standalone docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Jul 20, 2022
1 parent 8213a4a commit 6ceeb7d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/preview-web/src/PreviewWeb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2935,6 +2935,45 @@ describe('PreviewWeb', () => {
expect(mockChannel.emit).toHaveBeenCalledWith(STORY_RENDERED, 'component-one--a');
});
});

describe('when a standalone docs file changes', () => {
const newStandaloneDocsExports = { default: jest.fn() };

const newImportFn = jest.fn(async (path) => {
return path === './src/Introduction.mdx' ? newStandaloneDocsExports : importFn(path);
});

it('renders with the generated docs parameters', async () => {
document.location.search = '?id=introduction--docs&viewMode=docs';
const preview = await createAndRenderPreview();
mockChannel.emit.mockClear();
docsRenderer.render.mockClear();

preview.onStoriesChanged({ importFn: newImportFn });
await waitForRender();

expect(docsRenderer.render).toHaveBeenCalledWith(
expect.any(Object),
expect.objectContaining({
page: newStandaloneDocsExports.default,
renderer: projectAnnotations.parameters.docs.renderer,
}),
'docs-element',
expect.any(Function)
);
});

it('emits DOCS_RENDERED', async () => {
document.location.search = '?id=introduction--docs&viewMode=docs';
const preview = await createAndRenderPreview();
mockChannel.emit.mockClear();

preview.onStoriesChanged({ importFn: newImportFn });
await waitForRender();

expect(mockChannel.emit).toHaveBeenCalledWith(DOCS_RENDERED, 'introduction--docs');
});
});
});

describe('onGetProjectAnnotationsChanged', () => {
Expand Down

0 comments on commit 6ceeb7d

Please sign in to comment.