Skip to content

Commit f94f13a

Browse files
committed
chore: add JS tests with mocha and chai
This commit adds a JS unit testing framework with mocha and chai. Sample unit tests are provided for Comment and CommentList. Also updates react to 0.14.1 to satisfy a test-utils dependency
1 parent 98894c7 commit f94f13a

File tree

10 files changed

+519
-2724
lines changed

10 files changed

+519
-2724
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/public/assets
1818
.env
1919
node_modules
20-
npm-debug.log
20+
npm-debug.log*
2121
/coverage
2222

2323
# Ignore bundle dependencies

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ module.exports = {
183183
// And update this
184184
styleLoader: 'style-loader!css-loader!sass-loader?imagePath=/assets/images&includePaths[]=' + bourbonPaths,
185185
```
186-
- `@import 'bourbon';` Import bourbon from your [scss file](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/assets/stylesheets/_app-styling-post-bootstrap-loading.scss)
186+
- `@import 'bourbon';` Import bourbon from your [scss file](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/assets/stylesheets/_app-styling-post-bootstrap-loading.scss)
187187

188188
# Notes on Rails assets
189189
## Rails Asset Pipeline Magic
@@ -260,11 +260,31 @@ git push heroku master
260260
```
261261

262262
# Running Tests
263-
*Default rake task runs tests and linting*
263+
*Default rake task runs feature specs, mocha tests and linting*
264264

265-
We have feature tests in /spec/features
265+
We have;
266+
267+
* feature tests in /spec/features
268+
* component unit tests in /client/test/
269+
* javascript linting
270+
271+
From the root of the project, you can run all specs+tests+linter with
272+
273+
npm run test
274+
275+
Run the feature specs individually with `rspec`.
276+
277+
Run the React unit tests (all .js and .jsx files) from the `client` dir with;
278+
279+
cd client
280+
npm run test --silent
281+
282+
In lieu of having `mocha --watch` working properly (pull request welcome!), you can have your js tests continually running with `watch`
283+
284+
npm install -g watch
285+
cd client
286+
watch 'npm run test --silent' test/ app/
266287

267-
Run the tests with `rspec`.
268288

269289
## CI configuration
270290
Add those lines to your CI scripts after `bundle install`

client/.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ plugins:
99
env:
1010
browser: true
1111
node: true
12+
mocha: true
1213

1314
rules:
1415
indent: [1, 2, { SwitchCase: 1, VariableDeclarator: 2 }]

client/app/components/Comment.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const Comment = React.createClass({
1717
<h2 className="comment-author">
1818
{author}
1919
</h2>
20-
<span dangerouslySetInnerHTML={{__html: rawMarkup}}/>
20+
<span dangerouslySetInnerHTML={{__html: rawMarkup}} className="comment-text"/>
2121
</div>
2222
);
2323
},

0 commit comments

Comments
 (0)