Coder Social home page Coder Social logo

storybook-snapper's Introduction

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}/>)
});

storybook-snapper's People

Contributors

github-sheriff avatar shlomitc avatar wix-holt avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.