Skip to content
Chainable, easy to read, React testing library
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.
.babelrc Enforce no semicolon and fix lint errors Sep 27, 2015
.eslintrc updated for React v.14, only one problem Oct 7, 2015
.gitignore updated for alt store tests Oct 5, 2015
.npmignore added more files to npm ignore Sep 18, 2015 updated the readme Feb 19, 2016
circle.yml added circle.yml Sep 15, 2015

##Legit Tests

This is a super friendly testing library for React, inspired by express middleware, it's easily extendable. Why did I make this when you can use React's Test Utils? Because who likes typing out scryRenderedDOMComponentsWithTag and the other method names on there. Not only that, but setting up the render process is also a hassle.


npm install legit-tests --save


import Test from 'legit-tests'
import Test from 'legit-tests/no-dom' //don't include jsdom

import { expect } from 'chai'
import sinon from 'sinon'
import TestComponent from './TestComponent'

let spy = sinon.spy()

//Calling a prop
Test(<TestComponent onClick={spy}/>)
.simulate({method: 'click', element: 'button'})
.test(() => {

//finding an element
.elements('.box', (box) => {
  expect(box.props.children)'found me!')


Current list of Middleware

You can write middleware to do anything you repeatedly use. You can pass .use a function, along with an object that it will take in. Each function will be injected with the current instance which includes:

  • component - the actual component itself
  • instance - the rendered component instance
  • helpers - an array you can add on to with data for the end function


  • See mixin below, this syntax may soon be deprecated

This is the setState function used above.

Test(<TestComponent onClick={spy}/>)
.use(SetState, {})


export default function setState(state){


The .test function will be given the component instance and the helpers array. You can use a regular function to reference this or an arrow function:

.test(({helpers, instance}) => { ... })
.test(function() {
  //this.instance, this.helpers


Use .element if you're just testing an element you found with the .find method. The syntax is a little smaller:

.element(box => {
  expect(box.props.children)'found me!')
//or specify the element

.element('.box', box => {
  expect(box.props.children)'found me!')


Use .mixin if you want to add new middleware as methods to Test. This gives a more natural way of using middleware:

// In this example, CustomFind middleware was added to Test by mixin
// and used if as it was a method on Test itself.

Test(<TestComponent />)
  customFind: CustomFind
.customFind('cells', 'table td')
.element('cells', cells => {

##DOM rendering Shallow -- uses React shallow rendering (no DOM)

Test(<TestComponent onClick={spy}/>, {shallow: true})
.simulate({method: 'click', element: 'button'})
.test(() => {

Normal -- React render into document fragment

Test(<TestComponent onClick={spy}/>)
.simulate({method: 'click', element: 'button'})
.test(() => {

fullDOM -- ReactDOM render into document.body.div of jsdom

Test(<section />, {fullDOM: true})
.test(function() {
.clean() // restores the document.body to empty

You can see more examples in the tests directory.

##Testing Alt Stores

You can now test Alt stores using the same API.

import TestStore from 'legit-tests/alt/store'

TestStore(MyStore, MyActions)
.setInitialState({ todos: todos })
.addTodo({ title: "Get Beer", complete: false })
.test(({ state }) => {

You can see the full documentation on the Wiki

You can’t perform that action at this time.