Git Product home page Git Product logo

snap-it's Introduction

snap-it

npm version

This is a tool to create a snapshot for your component. You can use it to simply generate boilerplate file with all cases. Keep in mind that you should verify and add your own test cases.

Works only with TypeScript for now.

Usage:

Follow instalation guide and then:

yarn create-snapshot components/Search.tsx

Or you can use it directly without installing:

npx @patys/snap-it g components/Search.tsx

To save in the same directory use option: --direct=true

npx @patys/snap-it g components/Search.tsx --direct=true

Effect with direct: components/Search.tsx components/Search.test.tsx

Effect without direct: components/Search.tsx __tests__/Search.test.tsx

Installation:

yarn add --dev @patys/snap-it

Add to your package.json

{
  "scripts": {
    ...
    "create-snapshot": "yarn snap-it g "
    ...
  }
}

Example:

Your component:

// example/Search.tsx
import React from 'react';
import { View } from 'react-native';

interface Props {
  numberTest?: number;
  booleanTest?: boolean;
  stringTest?: string;
  anyTest?: any;
  functionTest?: () => void;

  requiredTest: string;
}

export default function Search({}: Props) {
  return <View />;
}

Effect:

import React from 'react';
import { render } from '@testing-library/react-native';

import { Search } from '../example/Search.tsx';

describe('Search', () => {
  test('Snaphot for required props', () => {
    const props = {
      requiredTest: 'testing string',
    };
    const tree = render(<Search {...props} />).toJSON();
    expect(tree).toMatchSnapshot();
  });

  test('Snaphot for numberTest', () => {
    const props = {
      requiredTest: 'testing string',

      numberTest: 123,
    };
    const tree = render(<Search {...props} />).toJSON();
    expect(tree).toMatchSnapshot();
  });

  test('Snaphot for booleanTest', () => {
    const props = {
      requiredTest: 'testing string',

      booleanTest: true,
    };
    const tree = render(<Search {...props} />).toJSON();
    expect(tree).toMatchSnapshot();
  });

  test('Snaphot for stringTest', () => {
    const props = {
      requiredTest: 'testing string',

      stringTest: 'testing string',
    };
    const tree = render(<Search {...props} />).toJSON();
    expect(tree).toMatchSnapshot();
  });

  test('Snaphot for anyTest', () => {
    const props = {
      requiredTest: 'testing string',

      anyTest: {},
    };
    const tree = render(<Search {...props} />).toJSON();
    expect(tree).toMatchSnapshot();
  });

  test('Snaphot for functionTest', () => {
    const props = {
      requiredTest: 'testing string',

      functionTest: jest.fn(),
    };
    const tree = render(<Search {...props} />).toJSON();
    expect(tree).toMatchSnapshot();
  });
});

snap-it's People

Contributors

patys avatar idaszakdaniel avatar

Stargazers

Paweł Schmidt avatar  avatar Dawid Przydróżny avatar Joanna Jasnowska avatar Natalia avatar  avatar Utku avatar Patrick Luzolo avatar Leo Farias avatar Marcin Kornek avatar  avatar

Watchers

James Cloos avatar Patrick Luzolo avatar  avatar

Forkers

idaszakdaniel

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.