Skip to content

futuregraph/react-tdd-guide

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-tdd-guide

A series of examples on how to TDD React

Getting started

  1. install nvm
  2. install io.js: nvm install io.js
    • Why io.js instead of node.js? The latest versions of jsdom only work with io.js. jsdom allows us to test without a browser and a test runner. Pre-4.x versions of jsdom, which run on node.js require contextify, which is a pain to setup on a windows machine.
  3. Grab an editor or IDE. I recommend Webstorm, Atom, and VIM, in that order.
  4. git clone ...
  5. npm i
  6. If using Webstorm, when configuring the mocha run configuration, add the following under "Extra Mocha options": -r ./lib/jsdom.js --compilers jsx:jsx-require-extension

How to use this guide

Each section is broken out into its own folder, starting with basics. What you'll find there is the finished example. I am experimenting with using the commit history and comments to drive the guide itself. Feedback on whether this works or not would be appreciated.

Each commit that is suffixed with "- red" can be checked out separately to examine the failing test. Each commit that is suffixed with "- green" shows how I finally passed the failing assertion.

Looking at the history for each section will show you only the steps needed to drive that part of the application.

Philosophy

  • Avoid the need for runners and browsers
  • Use a mostly mockist approach
    • Achieved using proxyquire and sinon

Table of Contents

  • Basics - Steps for TDD'ing the simplest of React components: An unordered list of items. Start here if you're not familiar with TDD'ing React and want to see a simple introduction. (WIP)
  • Simple event handling (not done)
  • Centralized state management techniques (not done)
  • Server interactions with Ampersand collections and models (not done)
  • React router (not done)

Running the tests for a section

  • npm run <section name>

Running all tests

  • npm test

Contributing

Please feel free to open an issue for:

  • A question on how to do something
  • A request for further clarification

Use a pull request for

  • Suggestions on changing how something is tested
  • To add an example you think would be valuable

Caveats

I am not a windows user, therefore this has only been tested on OSX.

About

A series of examples on how to TDD React

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%