Skip to content
This repository was archived by the owner on Apr 9, 2019. It is now read-only.

Commit 33015ac

Browse files
committed
Added test helpers
1 parent ecf6e1e commit 33015ac

File tree

7 files changed

+67
-2
lines changed

7 files changed

+67
-2
lines changed

karma.conf.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ module.exports = function(config) {
1313

1414
// list of files / patterns to load in the browser
1515
files: [
16+
'spec/helpers.js',
1617
'node_modules/react/dist/react-with-addons.js',
1718
'node_modules/sinon/pkg/sinon.js',
18-
'spec/**/*.{jsx,js}'
19+
'spec/**/*.spec.{jsx,js}'
1920
],
2021

2122
// list of files to exclude
@@ -24,7 +25,7 @@ module.exports = function(config) {
2425
// preprocess matching files before serving them to the browser
2526
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
2627
preprocessors: {
27-
'spec/**/*.{jsx,js}': ['webpack']
28+
'spec/**/*.spec.{jsx,js}': ['webpack']
2829
},
2930

3031
// test results reporter to use

spec/helpers.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
(function() {
2+
3+
var Ap = Array.prototype;
4+
var slice = Ap.slice;
5+
var Fp = Function.prototype;
6+
7+
if (!Fp.bind) {
8+
// PhantomJS doesn't support Function.prototype.bind natively, so
9+
// polyfill it whenever this module is required.
10+
Fp.bind = function(context) {
11+
var func = this;
12+
var args = slice.call(arguments, 1);
13+
14+
function bound() {
15+
var invokedAsConstructor = func.prototype && (this instanceof func);
16+
return func.apply(
17+
// Ignore the context parameter when invoking the bound function
18+
// as a constructor. Note that this includes not only constructor
19+
// invocations using the new keyword but also calls to base class
20+
// constructors such as BaseClass.call(this, ...) or super(...).
21+
!invokedAsConstructor && context || this,
22+
args.concat(slice.call(arguments))
23+
);
24+
}
25+
26+
// The bound function must share the .prototype of the unbound
27+
// function so that any object created by one constructor will count
28+
// as an instance of both constructors.
29+
bound.prototype = func.prototype;
30+
31+
return bound;
32+
};
33+
}
34+
35+
})();
36+
37+
(function() {
38+
39+
var lastTime = 0;
40+
var vendors = ['ms', 'moz', 'webkit', 'o'];
41+
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
42+
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
43+
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
44+
|| window[vendors[x]+'CancelRequestAnimationFrame'];
45+
}
46+
47+
if (!window.requestAnimationFrame) {
48+
window.requestAnimationFrame = function(callback, element) {
49+
var currTime = new Date().getTime();
50+
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
51+
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
52+
timeToCall);
53+
lastTime = currTime + timeToCall;
54+
return id;
55+
};
56+
}
57+
58+
if (!window.cancelAnimationFrame) {
59+
window.cancelAnimationFrame = function(id) {
60+
clearTimeout(id);
61+
};
62+
}
63+
64+
}());
File renamed without changes.

0 commit comments

Comments
 (0)