Skip to content

Instantly share code, notes, and snippets.

@screener-io
Created March 25, 2020 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save screener-io/ada0e3c51137c907ba80728ad7fab23b to your computer and use it in GitHub Desktop.
Save screener-io/ada0e3c51137c907ba80728ad7fab23b to your computer and use it in GitHub Desktop.
Storybook + Screener Steps with Hooks Example
import React from 'react';
import { Button } from '@storybook/react/demo';
import Screener, {Steps} from 'screener-storybook/src/screener';
export default {
title: 'Button',
component: Button,
};
export const Text = () => <Button>Hello Button</Button>;
// Hooks example
export const Emoji = () => {
const [state, setState] = React.useState(5);
return (
<Button onClick={() => setState(state + 1)}>
<span role="img" aria-label="so cool">
😀 😎 👍 💯
</span>
</Button>
);
};
// Add decorator with Screener steps and wrap storyFn in try/catch
Emoji.story = {
decorators: [storyFn => (
<Screener steps={new Steps()
.click('.selector')
.snapshot('name')
.end()
}>
{(() => {
try { return storyFn(); } catch(e) {}
})()}
</Screener>
)]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment