• Stars
    star
    188
  • Rank 205,563 (Top 5 %)
  • Language
    JavaScript
  • Created over 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Slides, notes and sample project from a talk on testing React applications given at the London React meetup group

OBSOLETE ADVICE WARNING

(Update on 2020-04-22): This talk was given a long time ago. Tools and best practices have evolved since then. For more up-to-date information, have a look at:

React Testability

This is a simple Twitter client project which demonstrates various tools and techniques for writing tests for React components, written as part of a talk (slides, video) at the London React meetup.

It shows the essentials for writing tests for a React application that can be run in Node and the browser, isolating modules under test using shallow rendering and rewire() and using Flummox for testable use of the Flux architecture.

Requirements

  • NodeJS 4.x or later is required in order to use the current version of the jsdom library.

Building and running

npm install .
make

# run the app
# (you can also use 'webpack-dev-server')
python -m SimpleHTTPServer 8000
open http://localhost:8000

# run tests in the browser
open tests.html

# run tests on the command-line
make test

Libraries and Tools Used

  • React (obviously). v0.13 is used for shallow-rendering support which enables testing of rendering of a single level of the component tree in isolation. Update (28/02/16): Shallow rendering support has since improved in React v0.14.7 to include some support for stateful components
  • Mocha and chai are the basic testing frameworks used, these were chosen as they are popular, polished and well documented.
  • Webpack is used to package the tests for running/debugging in the browser.
  • jsdom is used for testing of rendering DOM components outside of the browser.
  • The Flummox implementation of the Flux architecture is used for fetching data and updating views in response. Flummox avoidance of singletons makes it easy to inject fake/mock actions in unit and integration tests. Update (28/02/16): Flummox still works perfectly well, but Redux has since become the de-facto choice for state management in the React community and it has an even better testability story.
  • Rewire is used to show one approach to mocking out React components in tests. Update (28/02/16): I would probably recommend looking at inject-loader for Webpack or Proxyquire for Browserify instead as these provide a cleaner way to mock JS modules in my view.
  • isomorphic-fetch provides a uniform API for fetching data in the browser and Node.

Recommended Reading & Videos

More Repositories

1

webpack-bundle-size-analyzer

A tool for finding out what contributes to the size of Webpack bundles
TypeScript
1,400
star
2

Qt-Inspector

Utility to browse the Qt object tree of a running Qt application and edit object properties on the fly.
C++
375
star
3

passcards

A 1Password-compatible command-line and web-based password manager
TypeScript
137
star
4

tex-linebreak

JavaScript implementation of the Knuth-Plass linebreaking algorithm
TypeScript
110
star
5

tesseract-wasm

JS/WebAssembly build of the Tesseract OCR engine for use in browsers and Node
TypeScript
110
star
6

qt-mustache

Mustache templating library for C++ using Qt
C++
85
star
7

1pass

1Password command-line client
Go
66
star
8

konsole

Terminal for KDE
C++
60
star
9

approx-string-match-js

Approximate string matching library for JavaScript
TypeScript
35
star
10

ts-style

A small library for defining CSS classes using JavaScript or TypeScript
TypeScript
33
star
11

qt-maybe

Implementation of sum/option types using QVariant
C++
29
star
12

qt-signal-tools

Utility classes related to Qt signal and slot handling
C++
24
star
13

rollup-cache

Disk caching to speed up Rollup builds
JavaScript
15
star
14

mandrawer

A miscellaneous collection of scripts I use across various devices.
Python
13
star
15

sass-unused

Utility for finding unused variables in a collection of SASS files
JavaScript
12
star
16

extension-tools

A collection of scripts for automated publishing of browser extensions
JavaScript
11
star
17

kdevelop

KDevelop IDE
C++
10
star
18

babel-plugin-mockable-imports

Babel plugin that enables mocking of ES and CommonJS imports in tests
JavaScript
10
star
19

idb-mutex

Mutual exclusion (locks) between tabs in browsers using IndexedDB
TypeScript
9
star
20

xar-js

A JavaScript library for generating xar archives
TypeScript
8
star
21

dbpro-bluegui

BlueGUI v2 GUI controls plugin for DarkBASIC Professional
C++
7
star
22

rust-optparse

Command-line option parsing lib for Rust
Rust
3
star
23

duckface

Go-like interface generator for C++
Ruby
2
star
24

ureact

A small implementation of the modern React API for educational purposes.
JavaScript
2
star
25

unroll-it

Helper for creating data-driven / parametrized tests with Mocha
JavaScript
2
star
26

textgen

Random text generator built with PyTorch
Python
2
star
27

hot-reloading-talk

A talk for LondonJS on architecting web applications to enable hot reloading
JavaScript
2
star
28

elm-arch-tutorial

Notes made whilst working through the Elm Architecture Tutorial
Elm
1
star
29

talks

Slides and resources for talks I've given or will give
JavaScript
1
star
30

elm-april-hack-night

Elm
1
star
31

rd

A tool for quick access to recently used directories
Go
1
star
32

qt-webitemview

Qt item view delegate which uses WebKit to render item content
C++
1
star
33

find-unused-css-classes

Tool for finding CSS classes that are styled by selectors in a set of CSS files but not used
JavaScript
1
star
34

rust-cmacros

Rust lib for parsing macros from C header files and assisting with translation to Rust code
Rust
1
star
35

labnotes

A river-of-news feed aggregator. Created as a Mendeley hackday project.
TypeScript
1
star
36

used-css-classes

Tool that prints the list of unique CSS classes used in a set of HTML files or templates
Python
1
star
37

gomendeley

A basic demo showing authentication and use of the Mendeley API with Go
Go
1
star
38

prune-merged-branches

Tool to clean up your local Git branches
Python
1
star