1.0.67 • Published 3 years ago

storybook-snapper v1.0.67

Weekly downloads
127
License
MIT
Repository
-
Last release
3 years ago

storybook-snapshot

A utility library originally created as an accompanying tool for eyes-storybook.

The idea is to write snapshot tests as describe/it test suites like in familiar testing frameworks. Each test suite creates a storybook story, which eyes-storybook, in turn, takes a snapshot of.

This library relies on some of eyes-storybook's methods, however, it does not depend on eyes-storybook, which means it can be used just for generating stories.

Usage

Install with

npm install --save-dev storybook-snapper

or

yarn add --dev storybook-snapper

For testing, use the applitoolsConfig method in your applitools.config.js file, in order to generate a preconfigured configuration. This configuration is necessary for async tests to work.

In you applitools.config.js file:

const applitoolsConfig = require('storybook-snapper/config/applitools.config');

// optional local configuration file for overrides
let config;

try {
  // for local testing you can add the `apiKey` to your private configuration file
  config = require('./applitools.private.config.js');
} catch (e) {}

// Note that the `appName` property is required
module.exports = applitoolsConfig({config});

In your visual/story file:

import React from 'react';
import { visualize, story, snap, xsnap } from 'storybook-snapper';
import { MyComponent } from 'path/to/MyComponent';

visualize('MyComponent', () => {
    story('basic story', () => {
        snap('simple render', <MyComponent/>);
        snap('as a function', () => <MyComponent/>);
    });

    story('another story', () => {
        class AsyncStoryWrapper extends React.Component {
            componentDidMount() {
                setTimeout(() => {
                    this.props.onDone();
                }, 3000);
            }

            render() {
                return <MyComponent/>;
            }
        }

        snap('async story', done => <AsyncStoryWrapper onDone={done}/>);
    });

    snap('only one level of nesting', <MyComponent/>);

    /**
    * when used with eyes-storybook,
    * a snapshot can be ignored with xsnap
    */
    snap.skip('ignore this test', <MyComponent/>);

    /**
    * alias for "snap.skip"
    */
    xsnap('ignore this test', <MyComponent/>);

    /**
    * adds a red outline when a snapshot is taken
    * helpful for debugging async stories
    */
    snap.debug('debug story', done => <AsyncStoryWrapper onDone={done}/>)
});
1.0.67

3 years ago

1.0.66

3 years ago

1.0.65

3 years ago

1.0.64

4 years ago

1.0.63

4 years ago

1.0.62

4 years ago

1.0.61

4 years ago

1.0.60

4 years ago

1.0.59

4 years ago

1.0.58

4 years ago

1.0.57

4 years ago

1.0.56

4 years ago

1.0.55

4 years ago

1.0.54

4 years ago

1.0.53

4 years ago

1.0.52

4 years ago

1.0.51

4 years ago

1.0.50

4 years ago

1.0.48

4 years ago

1.0.49

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.45

4 years ago

1.0.44

4 years ago

1.0.43

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.40

4 years ago

1.0.39

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.9

4 years ago

1.0.10

4 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago