Skip to content

Commit 218ca0c

Browse files
committed
Merge pull request #8 from sfdc-matrix/mocha
Add Test Fixtures + Basic PicklistBase Test
2 parents 478a7fe + 80e50ad commit 218ca0c

File tree

6 files changed

+183
-7
lines changed

6 files changed

+183
-7
lines changed

karma.conf.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
var webpack = require('webpack');
2+
var webpackConfig = require('./webpack.dev.config');
3+
webpackConfig.devtool = 'inline-source-map';
4+
5+
// Karma configuration
6+
// Generated on Thu Oct 01 2015 08:45:20 GMT-0700 (PDT)
7+
8+
module.exports = function(config) {
9+
config.set({
10+
11+
// base path that will be used to resolve all patterns (eg. files, exclude)
12+
basePath: '',
13+
14+
15+
// frameworks to use
16+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
17+
frameworks: ['mocha', 'chai-sinon'],
18+
19+
20+
// list of files / patterns to load in the browser
21+
files: [
22+
'tests/fixtures/phantomjs-shims.js',
23+
'tests/tests_bundle.js'
24+
],
25+
26+
27+
// list of files to exclude
28+
exclude: [
29+
],
30+
31+
32+
// preprocess matching files before serving them to the browser
33+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
34+
preprocessors: {
35+
'tests/tests_bundle.js': ['webpack','sourcemap']
36+
},
37+
38+
39+
// test results reporter to use
40+
// possible values: 'dots', 'progress'
41+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
42+
reporters: ['progress'],
43+
44+
45+
// web server port
46+
port: 9876,
47+
48+
49+
// enable / disable colors in the output (reporters and logs)
50+
colors: true,
51+
52+
53+
// level of logging
54+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
55+
logLevel: config.LOG_INFO,
56+
57+
58+
// enable / disable watching file and executing tests whenever any file changes
59+
autoWatch: true,
60+
61+
62+
// start these browsers
63+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
64+
browsers: ['Chrome', 'PhantomJS'],
65+
66+
67+
// Continuous Integration mode
68+
// if true, Karma captures browsers, runs the tests and exits
69+
singleRun: false,
70+
71+
webpack : webpackConfig,
72+
73+
74+
plugins: [
75+
require('karma-webpack'),
76+
require('karma-mocha'),
77+
require('karma-chai-sinon'),
78+
require('karma-sourcemap-loader'),
79+
require('karma-phantomjs-launcher'),
80+
require('karma-chrome-launcher')
81+
]
82+
})
83+
}

package.json

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,36 @@
3232
"main": "lib/index.js",
3333
"homepage": "https://github.com/salesforce-ux/design-system-react",
3434
"devDependencies": {
35+
"babel": "^5.8.23",
3536
"babel-core": "^5.4.7",
3637
"babel-eslint": "^3.1.9",
3738
"babel-loader": "^5.1.2",
38-
"babel": "^5.8.23",
39+
"chai": "^3.3.0",
3940
"css-loader": "^0.9.1",
4041
"eslint-plugin-react": "^2.3.0",
4142
"extract-text-webpack-plugin": "^0.8.2",
4243
"file-loader": "^0.8.4",
44+
"karma": "^0.13.10",
45+
"karma-chai-sinon": "^0.1.5",
46+
"karma-chrome-launcher": "^0.2.0",
47+
"karma-cli": "^0.1.1",
48+
"karma-mocha": "^0.2.0",
49+
"karma-phantomjs-launcher": "^0.2.1",
50+
"karma-sourcemap-loader": "^0.3.5",
51+
"karma-webpack": "^1.7.0",
52+
"mocha": "^2.3.3",
53+
"phantomjs": "^1.9.18",
4354
"raw-loader": "^0.5.1",
55+
"react": "^0.13.0",
4456
"react-hot-loader": "^1.2.7",
57+
"react-prism": "^1.4.1",
58+
"react-router": "^0.13.3",
59+
"sinon": "^1.17.1",
60+
"sinon-chai": "^2.8.0",
4561
"style-loader": "^0.9.0",
4662
"url-loader": "^0.5.6",
4763
"webpack": "^1.9.6",
48-
"webpack-dev-server": "^1.8.2",
49-
"react-prism": "^1.4.1",
50-
"react-router": "^0.13.3"
64+
"webpack-dev-server": "^1.8.2"
5165
},
5266
"dependencies": {
5367
"classnames": "^2.1.3",
@@ -56,8 +70,5 @@
5670
"react-onclickoutside": "^0.3.0",
5771
"tether": "^1.1.0",
5872
"tether-drop": "^1.2.2"
59-
},
60-
"peerDependencies": {
61-
"react": "^0.13.0"
6273
}
6374
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const React = require('react/addons');
2+
const TestUtils = React.addons.TestUtils;
3+
import {SLDSPicklistBase} from '../../components';
4+
5+
describe('SLDSPicklistBase: ', function(){
6+
7+
let clickOnItem = (cmp, index) => {
8+
let items = TestUtils.scryRenderedDOMComponentsWithTag(
9+
cmp, 'a'
10+
);
11+
12+
TestUtils.Simulate.click(items[index]);
13+
};
14+
15+
it('onSelect fires upon selection change', sinon.test(function() {
16+
let onSelectStub = this.stub();
17+
let options = [
18+
{"value" : '1', "label" : '1'}
19+
];
20+
21+
let cmp = TestUtils.renderIntoDocument(
22+
<SLDSPicklistBase options={options} onSelect={onSelectStub}/>
23+
);
24+
25+
let button = TestUtils.findRenderedDOMComponentWithTag(
26+
cmp, 'button'
27+
);
28+
29+
TestUtils.Simulate.click(button);
30+
clickOnItem(cmp, 0);
31+
32+
expect(onSelectStub.calledOnce).to.be.ok;
33+
expect(onSelectStub.calledWith('1')).to.be.ok;
34+
}));
35+
});

tests/fixtures/phantomjs-shims.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(function() {
2+
//Src: https://gist.github.com/noradaiko/12cbaf8a1674e3b8c8e6
3+
4+
var Ap = Array.prototype;
5+
var slice = Ap.slice;
6+
var Fp = Function.prototype;
7+
8+
if (!Fp.bind) {
9+
// PhantomJS doesn't support Function.prototype.bind natively, so
10+
// polyfill it whenever this module is required.
11+
Fp.bind = function(context) {
12+
var func = this;
13+
var args = slice.call(arguments, 1);
14+
15+
function bound() {
16+
var invokedAsConstructor = func.prototype && (this instanceof func);
17+
return func.apply(
18+
// Ignore the context parameter when invoking the bound function
19+
// as a constructor. Note that this includes not only constructor
20+
// invocations using the new keyword but also calls to base class
21+
// constructors such as BaseClass.call(this, ...) or super(...).
22+
!invokedAsConstructor && context || this,
23+
args.concat(slice.call(arguments))
24+
);
25+
}
26+
27+
// The bound function must share the .prototype of the unbound
28+
// function so that any object created by one constructor will count
29+
// as an instance of both constructors.
30+
bound.prototype = func.prototype;
31+
32+
return bound;
33+
};
34+
}
35+
36+
})();

tests/tests_bundle.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// tests/tests_bundle.js
2+
3+
// require all modules ending in ".test.js" or ".test.jsx" from the
4+
// current directory and all subdirectories
5+
var testsContext = require.context(".", true, /.test.(js|jsx)$/);
6+
testsContext.keys().forEach(testsContext);

webpack.dev.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ module.exports = {
3333
loaders: ['react-hot', 'babel'],
3434
include: [path.join(__dirname, 'demo'),path.join(__dirname, 'components')]
3535
},
36+
{
37+
test: /\.(js|jsx)?$/,
38+
loaders: ['react-hot', 'babel'],
39+
include: [path.join(__dirname, 'tests')]
40+
},
3641
{
3742
test: /\.css$/,
3843
loader: ExtractTextPlugin.extract("style-loader", "css-loader")

0 commit comments

Comments
 (0)