From 14d341c773c422aa0eb1df4e3fe3a8c0e6753d6b Mon Sep 17 00:00:00 2001 From: adjavaherian Date: Fri, 6 Mar 2015 11:59:59 -0800 Subject: [PATCH 1/7] ignore idea --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 59d842b..004c55c 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ node_modules # Users Environment Variables .lock-wscript +.idea From 8d94dcda42f5bd6f8ee304b8ca9c429ccfb456bc Mon Sep 17 00:00:00 2001 From: adjavaherian Date: Fri, 6 Mar 2015 15:47:39 -0800 Subject: [PATCH 2/7] Fully functional examples / specs for complicated React components --- README.md | 20 +++++----- package.json | 15 ++++++-- src/BigComplicatedComponent.js | 2 +- src/CheckboxWithLabel.js | 2 +- src/TestClass.jsx | 28 ++++++++++++++ src/flux/ActionsBundle.js | 8 ++++ src/flux/AppActions.js | 19 ++++++++++ src/flux/AppStore.js | 30 +++++++++++++++ src/flux/FluxConstructor.js | 28 ++++++++++++++ tests/CheckboxWithLabel-test.js | 33 ----------------- tests/blanket-stub-jsx.js | 65 --------------------------------- tests/bootstrap.js | 40 ++++++++++++++++++++ tests/compiler.js | 13 ------- tests/jsx-stub-transform.js | 47 ------------------------ tests/lib/TestContext.js | 46 +++++++++++++++++++++++ tests/spec1.js | 25 +++++++++++++ tests/spec2.js | 27 ++++++++++++++ tests/spec3.js | 27 ++++++++++++++ tests/testdom.js | 11 ------ 19 files changed, 302 insertions(+), 184 deletions(-) create mode 100644 src/TestClass.jsx create mode 100644 src/flux/ActionsBundle.js create mode 100644 src/flux/AppActions.js create mode 100644 src/flux/AppStore.js create mode 100644 src/flux/FluxConstructor.js delete mode 100644 tests/CheckboxWithLabel-test.js delete mode 100644 tests/blanket-stub-jsx.js create mode 100644 tests/bootstrap.js delete mode 100644 tests/compiler.js delete mode 100644 tests/jsx-stub-transform.js create mode 100644 tests/lib/TestContext.js create mode 100644 tests/spec1.js create mode 100644 tests/spec2.js create mode 100644 tests/spec3.js delete mode 100644 tests/testdom.js diff --git a/README.md b/README.md index bfd264d..c755e55 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ mocha-react =========== -Demo of using MochaJS to test a ReactJS component (with JSX and Harmony). +Demo of using MochaJS to test a ReactJS component (with JSX and Harmony and Flux and React-Router). This is a port of the [Jest React tutorial][1]. If you'd like to test your React JS components using Mocha instead of Jest, you can use this as a template. @@ -17,8 +17,8 @@ npm test What this template gets you: -- JSX/Harmony transpilation -- Opt-in module stubbing (ala Jest's "auto-mocking") +- JSX/Harmony transpilation with Babel +- React Component stubbing (ala Jest's pretty borked "auto-mocking") with Mockery and Sinon - Code coverage via Blanket and coveralls.io For more background and information on how this works, see [this blog post][5]. @@ -26,16 +26,14 @@ For more background and information on how this works, see [this blog post][5]. Here are the high order bits: - A fake DOM is provided via `jsdom` (see `tests/testdom.js`). -- `global.reactModulesToStub` contains a list of modules to replace with stubs (ala Jest). -- `tests/compiler.js` registers a compiler which transforms JSX/Harmony code to - standard ES5 JS and implements the stubbing. -- `tests/blanket-stub-jsx.js` applies the same transformations, additionally - instrumenting code for test coverage. The results are [posted to coveralls.io][4]. +- `global.reactStub` contains a mini React stub that you can use for mocking. +- `tests/TestContext.js` provides real Flux tests and simulated ReactRouter.Run, +- Additionally instrumenting code for test coverage. The results are [posted to coveralls.io][4]. -To run the tests using the `mocha` command line: +To run the tests using `npm test` or the `mocha` command line: ``` -mocha --compilers .:tests/compiler.js tests/*test.js +mocha tests/*.js --recursive --reporter spec ``` Inspiration and guidance came from the [Testing React Components][2] blog post and the Khan Academy's [React Components Makefile][3]. @@ -45,3 +43,5 @@ Inspiration and guidance came from the [Testing React Components][2] blog post a [3]: https://github.com/Khan/react-components/blob/master/Makefile [4]: https://coveralls.io/r/danvk/mocha-react?branch=master [5]: http://www.hammerlab.org +[6]: http://bulkan-evcimen.com/using_mockery_to_mock_modules_nodejs.html +[7]: https://github.com/FredKSchott/the-node-way diff --git a/package.json b/package.json index 338b982..0af1e06 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,27 @@ { "dependencies": { + "babel": "^4.6.6", + "fluxxor": "^1.5.1", + "jsdom": "^3.1.1", + "lodash": "~2.4.1", "react": "^0.12.2", + "react-router": "0.12.0", "react-tools": "^0.12.2" }, "devDependencies": { "blanket": "^1.1.6", "coveralls": "^2.11.2", "glob": "^4.3.5", - "jsdom": "^3.1.1", "mocha": "^2.0.1", - "mocha-lcov-reporter": "0.0.1" + "mocha-lcov-reporter": "0.0.1", + "assert": "^1.3.0", + "bower": "~1.3.12", + "fluxxor-test-utils": "^0.1.1", + "mockery": "^1.4.0", + "sinon": "^1.12.2" }, "scripts": { - "test": "mocha --compilers .:tests/compiler.js tests/*-test.js" + "test": "mocha tests/*.js --recursive --reporter spec" }, "config": { "blanket": { diff --git a/src/BigComplicatedComponent.js b/src/BigComplicatedComponent.js index 1aaf4b2..3076358 100644 --- a/src/BigComplicatedComponent.js +++ b/src/BigComplicatedComponent.js @@ -5,7 +5,7 @@ var React = require('react'); var BigComplicatedComponent = React.createClass({ render: function() { console.log('Thinking really hard!'); - return
42
; + return
42
; } }); diff --git a/src/CheckboxWithLabel.js b/src/CheckboxWithLabel.js index 75928d0..be76a23 100644 --- a/src/CheckboxWithLabel.js +++ b/src/CheckboxWithLabel.js @@ -10,7 +10,7 @@ var CheckboxWithLabel = React.createClass({ }, render: function() { return ( -