commit e92339c6b154168dba4aa3de631129b850841f83
parent ea149ee703e2399e951d894b3ef1a4245d648ae9
Author: Daniel Sont <dan.sont@gmail.com>
Date: Wed, 8 Oct 2014 09:50:16 +0800
Add Jest, Delete Karma
Diffstat:
6 files changed, 44 insertions(+), 79 deletions(-)
diff --git a/README.md b/README.md
@@ -94,6 +94,13 @@ $ git merge upstream/master
$ npm install
```
+### Running Unit Tests
+Jest tests are located in the __tests__ directory. Run them with this npm script:
+
+```shell
+$ npm test
+```
+
### Learn More
* [Getting Started with React.js](http://facebook.github.io/react/)
@@ -102,6 +109,7 @@ $ npm install
* [React.js Discussion Board](https://groups.google.com/forum/#!forum/reactjs)
* [Flux Architecture for Building User Interfaces](http://facebook.github.io/flux/)
* [The Future of React](https://github.com/reactjs/react-future)
+ * [Jest | Painless Unit Testing](http://facebook.github.io/jest/)
### Support
diff --git a/__tests__/component/Navbar-test.js b/__tests__/component/Navbar-test.js
@@ -0,0 +1,16 @@
+var __path__ = '../../src/components/Navbar.jsx';
+
+jest.dontMock(__path__);
+
+describe('NavBar', function() {
+ it('sets class name', function() {
+ var React = require('react/addons')
+ var TestUtils = React.addons.TestUtils;
+
+ var NavBar = require(__path__);
+ var Component = TestUtils.renderIntoDocument(<NavBar />);
+
+ var element = TestUtils.findRenderedDOMComponentWithClass(Component, 'navbar-top');
+ expect(element).toBeDefined();
+ });
+});
+\ No newline at end of file
diff --git a/config/karma.js b/config/karma.js
@@ -1,58 +0,0 @@
-/*!
- * Facebook React Starter Kit | https://github.com/kriasoft/react-starter-kit
- * Copyright (c) KriaSoft, LLC. All rights reserved. See LICENSE.txt
- */
-
-/*
- * Karma configuration. For more information visit
- * http://karma-runner.github.io/0.12/config/configuration-file.html
- */
-
-'use strict';
-
-var webpackConfig = require('./webpack.js')(/* release */ false);
-
-module.exports = function (config) {
- config.set({
-
- basePath: '../',
-
- files: [
- 'src/**/*Spec.jsx'
- ],
-
- preprocessors: {
- 'src/**/*Spec.jsx': ['webpack']
- },
-
- webpack: {
- cache: true,
- module: {
- loaders: webpackConfig.module.loaders
- }
- },
-
- webpackServer: {
- stats: {
- colors: true
- }
- },
-
- autoWatch: false,
-
- singleRun: true,
-
- frameworks: ['jasmine'],
-
- browsers: ['Chrome'],
-
- plugins: [
- 'karma-chrome-launcher',
- 'karma-firefox-launcher',
- 'karma-phantomjs-launcher',
- 'karma-jasmine',
- 'karma-webpack'
- ]
-
- });
-};
diff --git a/config/preprocessor.js b/config/preprocessor.js
@@ -0,0 +1,11 @@
+var ReactTools = require('react-tools');
+
+module.exports = {
+ process: function(src, path) {
+ if (path.match(/\.jsx?$/)) {
+ src = ReactTools.transform('/** @jsx React.DOM */' + src, {harmony: true});
+ } else src = '';
+
+ return src;
+ }
+};
+\ No newline at end of file
diff --git a/package.json b/package.json
@@ -34,30 +34,30 @@
"gulp-size": "^1.1.0",
"gulp-uglify": "^1.0.1",
"gulp-util": "^3.0.1",
+ "jest-cli": "^0.1.18",
"jshint": "^2.5.6",
"jshint-loader": "^0.8.0",
"jshint-stylish": "^1.0.0",
"jsx-loader": "^0.11.2",
- "karma": "^0.12.24",
- "karma-chrome-launcher": "^0.1.5",
- "karma-firefox-launcher": "^0.1.3",
- "karma-jasmine": "^0.1.5",
- "karma-phantomjs-launcher": "^0.1.4",
- "karma-webpack": "^1.2.2",
"merge-stream": "^0.1.6",
"minimist": "^1.1.0",
"protractor": "^1.3.1",
"psi": "^0.1.2",
+ "react-tools": "^0.11.2",
"run-sequence": "^1.0.1",
"url-loader": "^0.5.5",
"webpack": "^1.4.4",
"webpack-dev-server": "^1.6.5"
},
+ "jest": {
+ "scriptPreprocessor": "<rootDir>/config/preprocessor.js",
+ "unmockedModulePathPatterns": ["<rootDir>/node_modules/react"]
+ },
"scripts": {
"prestart": "npm install",
"start": "gulp",
"pretest": "npm install",
- "test": "karma start ./config/karma.js --single-run",
+ "test": "jest",
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update"
}
diff --git a/src/components/NavbarSpec.jsx b/src/components/NavbarSpec.jsx
@@ -1,14 +0,0 @@
-'use strict';
-
-describe('Navbar', () => {
- var Navbar, component;
-
- beforeEach(() => {
- Navbar = require('./Navbar.jsx');
- component = Navbar();
- });
-
- it('should create a new instance of Navbar', () => {
- expect(component).toBeDefined();
- });
-});