about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKai Schaper <303@posteo.de>2016-10-10 04:01:10 +0200
committerKai Schaper <303@posteo.de>2016-10-10 22:48:58 +0200
commitd7c55853e9d180290ae3cb30b2f329ebab8748ce (patch)
tree9db1d8353db63018a02065c8d3d55318ddc796d2
parent77efdfa1104a77061f014bbc84268028597620cb (diff)
set up Mocha/Chai/Enzyme for React component unit testing
-rw-r--r--.nvmrc1
-rw-r--r--package.json14
-rw-r--r--spec/javascript/components/loading_indicator.test.jsx13
3 files changed, 24 insertions, 4 deletions
diff --git a/.nvmrc b/.nvmrc
new file mode 100644
index 000000000..f0e13c509
--- /dev/null
+++ b/.nvmrc
@@ -0,0 +1 @@
+6.7.0
diff --git a/package.json b/package.json
index 1ea514e1f..f5244a2b0 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,10 @@
 {
   "name": "mastodon",
+  "scripts": {
+    "test": "mocha --compilers js:babel-register ./spec/javascript/components/*.test.jsx"
+  },
   "devDependencies": {
+    "axios": "^0.14.0",
     "babel-plugin-react-transform": "^2.0.2",
     "babel-plugin-transform-object-rest-spread": "^6.8.0",
     "babel-preset-es2015": "^6.13.2",
@@ -8,17 +12,19 @@
     "babelify": "^7.3.0",
     "browserify": "^13.1.0",
     "browserify-incremental": "^3.1.1",
-    "react": "^15.3.0",
-    "react-dom": "^15.3.0",
-    "react-proxy": "^1.1.8",
-    "axios": "^0.14.0",
+    "chai": "^3.5.0",
+    "enzyme": "^2.4.1",
     "es6-promise": "^3.2.1",
     "immutable": "^3.8.1",
+    "mocha": "^3.1.1",
     "moment": "^2.14.1",
     "react-addons-perf": "^15.3.2",
     "react-addons-pure-render-mixin": "^15.3.1",
+    "react-addons-test-utils": "^15.3.2",
+    "react-dom": "^15.3.0",
     "react-immutable-proptypes": "^2.1.0",
     "react-notification": "^6.1.1",
+    "react-proxy": "^1.1.8",
     "react-redux": "^5.0.0-beta.3",
     "react-redux-loading-bar": "^2.3.3",
     "react-router": "^2.8.0",
diff --git a/spec/javascript/components/loading_indicator.test.jsx b/spec/javascript/components/loading_indicator.test.jsx
new file mode 100644
index 000000000..b2f9c919e
--- /dev/null
+++ b/spec/javascript/components/loading_indicator.test.jsx
@@ -0,0 +1,13 @@
+import { expect } from 'chai';
+import { shallow } from 'enzyme';
+import React from 'react';
+global.React = React;
+
+import LoadingIndicator from '../../../app/assets/javascripts/components/components/loading_indicator'
+
+describe('<LoadingIndicator />', function() {
+  it('renders text that indicates loading', function() {
+    const wrapper = shallow(<LoadingIndicator />);
+    expect(wrapper.text()).to.match(/loading/i);
+  });
+});