nicholas
nicholas

Reputation: 14563

TDD Browserify and ReactJS

I'm trying to find a good, clean, way to test React components. I'm liking the idea of mochify as it looks like it abstracts a lot of the hassle of test runners, works with webdriver/saucelabs, etc.

The trouble is that I'm using Browserify with various transforms for jsx, coffee, less, etc from the command line. And can't find how get mochify to run those transforms.

How do I do this?

Or is there a better option out there... Karma maybe?

Thanks

Upvotes: 1

Views: 2238

Answers (2)

mantoni
mantoni

Reputation: 1622

Edit: Mochify now supports additional transforms and plugins with --transform and --plugin.

This problem will be addressed in a future release of Mochify.

Make sure to watch the issue on GitHub.

Upvotes: 1

tungd
tungd

Reputation: 14897

Browserify transforms can also be specified in package.json, for example:

...
"devDependencies": {
  "browserify": "*",
  "coffeeify": "^0.6.0",
  "mocha": "*",
  "mochify": "*",
  "reactify": "^0.13.1"
},
"browserify": {
  "transform": [
    "coffeeify",
    "reactify"
  ]
},
...

In your test files, just requires the actual component file using relative path, and write tests as you normally do with mocha:

var React = require('react/addons');
var TestUtils = React.addons.TestUtils;
var MyComponent = require('../src/app/MyComponent');
...

Upvotes: 2

Related Questions