GithubHelp home page GithubHelp logo

jesse-spevack / react-tdd-exercises Goto Github PK

View Code? Open in Web Editor NEW

This project forked from biglovisa/react-tdd-exercises

0.0 0.0 0.0 15 KB

Test suites to practice tdd:ing react components

HTML 1.48% JavaScript 98.52%

react-tdd-exercises's Introduction

React TDD examples

A repository with test suites for React components.

Testing tools: Enzyme, Mocha, Chai


Up and running

In your terminal, clone the repository and install the dependencies:

$ git clone [email protected]:applegrain/react-tdd-exercises.git
$ cd react-tdd-exercises
$ npm install

How-to

In ./test there are enumerated test suites, and every test in the suites are skipped. Work with one test suite at a time, starting with 00-hello-world. Unskip one test at a time and write code to make it pass.


Running the tests

To run the entire test suite:

$ npm test

To run a specific test, chain the .only() function call to your it block.

it.only("contains a div with class `hello-world`", function() {
    expect(shallow(<HelloWorld />).contains(<div className="hello-world" />)).to.equal(true);
  });

The same applies for describe block:

describe.only("Component: Hello World", function() {

  ...

});

To exclude some tests or test suites from running with the entire test suite, add the .skip() call to either it or describe blocks.

You can also add prepend it and describe blocks with an x:

describe.only("Component: Hello World", function() {

  xit.only("contains a div with class `hello-world`", function() {
      expect(shallow(<HelloWorld />).contains(<div className="hello-world" />)).to.equal(true);
  });

});

Browser debugging

If you want to debug your component from the browser, open src/index.js and change the imported component on line 4 to the one you are working with. Then, run webpack from your browser to bundle your code, and then open index.html.

From your terminal, run:

$ webpack
$ open index.html

About the tools

  • React: a rendering library
  • Enzyme: a testing utility library for React
  • Mocha: a JavaScript testing framework
  • Chai: a JavaScript assertion library

react-tdd-exercises's People

Contributors

biglovisa avatar jesse-spevack 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.