Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 1.03 KB

README.md

File metadata and controls

30 lines (23 loc) · 1.03 KB

Testing React and Flux (McFly) with Mocha

Get going

  1. npm install
  2. mocha

Tools

  • Mocha for running tests
  • Chai for assertions
  • Sinon for stubs, spys, etc
  • Nock to mock external API calls
  • Rewire to mock require calls and to allow private method testing
  • Decache to help out with the Flux dispatcher being a singleton

Patterns

React Components

  • Use the React Test Utils
  • Use Rewire's __set__ method to mock nested React components. See - ParentTests.coffee for example.

Flux Stores

  • Use dispatcher.dispatch to dispatch fake actions
  • Use Rewire's __get__ method to expose private methods
  • See ItemStoreTests.coffee for examples

Flux Actions

  • Use Sinon Spys and spy on dispatcher.dispatch to make sure your actions are firing as expected

External API calls

  • Use Nock to mock any external APIs that are needed in your tests