Skip to content

Commit

Permalink
use isTestRunner in internal example
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Oct 6, 2022
1 parent d1bba72 commit b923816
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .storybook/preview.js
@@ -0,0 +1,11 @@
import { isTestRunner } from '../dist/esm/is-test-runner';

const withSkippableTests = (StoryFn, { parameters }) => {
if (parameters.test?.skip && isTestRunner()) {
return () => {};
}

return StoryFn();
};

export const decorators = [withSkippableTests];
23 changes: 23 additions & 0 deletions stories/atoms/Button.stories.js
@@ -1,5 +1,6 @@
import React from 'react';
import { expect } from '@storybook/jest';
import { isTestRunner } from '../../dist/esm/is-test-runner';
import { within, waitFor, userEvent, waitForElementToBeRemoved } from '@storybook/testing-library';

import { Button } from './Button';
Expand Down Expand Up @@ -109,3 +110,25 @@ WithLoaders.play = async ({ args, canvasElement }) => {
await userEvent.click(todoItem);
await expect(args.onSubmit).toHaveBeenCalledWith('delectus aut autem');
};

export const UserAgent = () => (
<div>
<p>
<strong>isTestRunner:</strong> {isTestRunner().toString()}
</p>
<p>
<strong>User agent:</strong> {window.navigator.userAgent}
</p>
</div>
);
UserAgent.play = async () => {
if (isTestRunner()) {
await expect(window.navigator.userAgent).toContain('StorybookTestRunner');
}
};
UserAgent.parameters = {
tests: {
skip: true,
disableSnapshots: true,
},
};

0 comments on commit b923816

Please sign in to comment.