Giter VIP home page Giter VIP logo

react-tc's Introduction

##This modules have 2 export functions:

  • setup - setup react component for testing
  • tc(test component) - test component by type & props & children length
import { setup, tc } from 'react-tc';
import React, { Component, PropTypes } from 'react';
import expect from 'expect';
import styles from './styles'; // scss file (if you use css modules)

/**
 * Simple component
 */
class YouComponent extends Component {

  static propTypes = {
    items: PropTypes.arrayOf(PropTypes.object).isRequired,
    callback: PropTypes.func.isRequired
  };

  render() {
    
    const { callback, items } = this.props;
  
    return (
      <div className={styles.general} onClick={callback}>
        {
          items.map((item) => {
            return (
              <h1 key={item.id} className={styles.item}>{item.name}</h1>
            );
          })
        }
      </div>
    );

  }

}

// %%%%%%%% TEST %%%%%%%%%%

/**
 * @return 
 *  {object} output - shallow render element
 *  {object} props - you passed props
 *  {object} context - you passed context
 */
const { output, props, context } = setup(YouComponent, {
  items: [{
    id: 1,
    name: 'one'
  }, {
    id: 2,
    name: 'two'
  }],
  callback: expect.createSpy()
});

/**
 * test first layer of output by their props and child length
 * if you child undefined, null, empty array [] - this is equal with 0 or miss 4 parameter tc function
 */
tc(output, 'div', {
  className: styles.general,
  onClick: props.callback
}, 2);

expect(props.callback.calls.length).toBe(0);
output.props.onClick();
expect(props.callback.calls.length).toBe(1);

const [item1, item2] = output.props.children;

tc(item1, 'h1', {
  children: props.items[0].name,
  className: styles.item
}, 1);

tc(item2, 'h1', {
  children: props.items[1].name,
  className: styles.item
}, 1);

react-tc's People

Contributors

ipostol avatar madzhup avatar

Watchers

 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.