Skip to content

Commit 8479e03

Browse files
committedJan 16, 2015
upgrade test libs
1 parent ac73aa1 commit 8479e03

File tree

7 files changed

+9927
-6404
lines changed

7 files changed

+9927
-6404
lines changed
 

‎tests/bind-shim.js

-26
This file was deleted.

‎tests/chai.js

+4,527-3,494
Large diffs are not rendered by default.

‎tests/happen.js

+71-49
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
!(function(context, $) {
2-
var h = {};
1+
!(function(context) {
2+
var h = {},
3+
events = {
4+
mouse: ['click', 'mousedown', 'mouseup', 'mousemove',
5+
'mouseover', 'mouseout'],
6+
key: ['keydown', 'keyup', 'keypress']
7+
},
8+
s, i;
39

410
// Make inheritance bearable: clone one level of properties
511
function extend(child, parent) {
@@ -11,10 +17,15 @@
1117
return child;
1218
}
1319

14-
h.once = function(x, o) {
15-
var evt;
20+
// IE<9 doesn't support indexOf
21+
function has(x, y) {
22+
for (var i = 0; i < x.length; i++) if (x[i] == y) return true;
23+
return false;
24+
}
1625

17-
if (o.type.slice(0, 3) === 'key') {
26+
h.makeEvent = function(o) {
27+
var evt;
28+
if (has(events.key, o.type)) {
1829
if (typeof Event === 'function') {
1930
evt = new Event(o.type);
2031
evt.keyCode = o.keyCode || 0;
@@ -59,65 +70,76 @@
5970
}
6071
}
6172
} else {
62-
evt = document.createEvent('MouseEvents');
63-
// https://developer.mozilla.org/en/DOM/event.initMouseEvent
64-
evt.initMouseEvent(o.type,
65-
true, // canBubble
66-
true, // cancelable
67-
window, // 'AbstractView'
68-
o.clicks || 0, // click count
69-
o.screenX || 0, // screenX
70-
o.screenY || 0, // screenY
71-
o.clientX || 0, // clientX
72-
o.clientY || 0, // clientY
73-
o.ctrlKey || 0, // ctrl
74-
o.altKey || false, // alt
75-
o.shiftKey || false, // shift
76-
o.metaKey || false, // meta
77-
o.button || false, // mouse button
78-
null // relatedTarget
79-
);
73+
if (typeof document.createEvent === 'undefined' &&
74+
typeof document.createEventObject !== 'undefined') {
75+
evt = document.createEventObject();
76+
extend(evt, o);
77+
} else if (typeof document.createEvent !== 'undefined') {
78+
// both MouseEvent and MouseEvents work in Chrome
79+
evt = document.createEvent('MouseEvents');
80+
// https://developer.mozilla.org/en/DOM/event.initMouseEvent
81+
evt.initMouseEvent(o.type,
82+
true, // canBubble
83+
true, // cancelable
84+
window, // 'AbstractView'
85+
o.detail || 0, // click count or mousewheel detail
86+
o.screenX || 0, // screenX
87+
o.screenY || 0, // screenY
88+
o.clientX || 0, // clientX
89+
o.clientY || 0, // clientY
90+
o.ctrlKey || 0, // ctrl
91+
o.altKey || false, // alt
92+
o.shiftKey || false, // shift
93+
o.metaKey || false, // meta
94+
o.button || false, // mouse button
95+
null // relatedTarget
96+
);
97+
}
8098
}
99+
return evt;
100+
};
81101

82-
x.dispatchEvent(evt);
102+
h.dispatchEvent = function(x, evt) {
103+
// not ie before 9
104+
if (typeof x.dispatchEvent !== 'undefined') {
105+
x.dispatchEvent(evt);
106+
} else if (typeof x.fireEvent !== 'undefined') {
107+
x.fireEvent('on' + evt.type, evt);
108+
}
83109
};
84110

85-
var shortcuts = ['click', 'mousedown', 'mouseup', 'mousemove',
86-
'mouseover', 'mouseout', 'keydown', 'keyup', 'keypress'],
87-
s, i = 0;
111+
h.once = function(x, o) {
112+
h.dispatchEvent(x, h.makeEvent(o || {}));
113+
};
88114

89-
while (s = shortcuts[i++]) {
90-
h[s] = (function(s) {
91-
return function(x, o) {
92-
h.once(x, extend(o || {}, { type: s }));
93-
};
94-
})(s);
115+
for (var type in events) {
116+
if (!events.hasOwnProperty(type)) continue;
117+
var shortcuts = events[type];
118+
for (i = 0; i < shortcuts.length; i++) {
119+
s = shortcuts[i];
120+
h[s] = (function(s) {
121+
return function(x, o) {
122+
h.once(x, extend(o || {}, { type: s }));
123+
};
124+
})(s);
125+
}
95126
}
96127

97128
h.dblclick = function(x, o) {
98-
h.once(x, extend(o || {}, {
99-
type: 'dblclick',
100-
clicks: 2
101-
}));
129+
h.once(x, extend(o || {}, { type: 'dblclick', detail: 2 }));
102130
};
103131

104-
this.happen = h;
105-
106-
// Export for nodejs
107-
if (typeof module !== 'undefined') {
108-
module.exports = this.happen;
109-
}
132+
if (typeof window !== 'undefined') window.happen = h;
133+
if (typeof module !== 'undefined') module.exports = h;
110134

111135
// Provide jQuery plugin
112-
if ($ && $.fn) {
113-
$.fn.happen = function(o) {
114-
if (typeof o === 'string') {
115-
o = { type: o };
116-
}
136+
if (typeof jQuery !== 'undefined' && jQuery.fn) {
137+
jQuery.fn.happen = function(o) {
138+
if (typeof o === 'string') o = { type: o };
117139
for (var i = 0; i < this.length; i++) {
118140
happen.once(this[i], o);
119141
}
120142
return this;
121143
};
122144
}
123-
})(this, (typeof jQuery !== 'undefined') ? jQuery : null);
145+
})(this);

‎tests/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<script src="chai.js"></script>
1212
<script src="sinon.js"></script>
1313
<script src="sinon-chai.js"></script>
14-
<script src="bind-shim.js"></script>
1514
<script src="happen.js"></script>
1615

1716
<!-- include source files here ... -->

‎tests/mocha.js

+1,358-488
Large diffs are not rendered by default.

‎tests/sinon-chai.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// Module systems magic dance.
55

6+
/* istanbul ignore else */
67
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
78
// NodeJS
89
module.exports = sinonChai;
@@ -26,6 +27,13 @@
2627
typeof putativeSpy.calledWithExactly === "function";
2728
}
2829

30+
function timesInWords(count) {
31+
return count === 1 ? "once" :
32+
count === 2 ? "twice" :
33+
count === 3 ? "thrice" :
34+
(count || 0) + " times";
35+
}
36+
2937
function isCall(putativeCall) {
3038
return putativeCall && isSpy(putativeCall.proxy);
3139
}
@@ -39,15 +47,21 @@
3947
function getMessages(spy, action, nonNegatedSuffix, always, args) {
4048
var verbPhrase = always ? "always have " : "have ";
4149
nonNegatedSuffix = nonNegatedSuffix || "";
42-
spy = spy.proxy || spy;
50+
if (isSpy(spy.proxy)) {
51+
spy = spy.proxy;
52+
}
4353

4454
function printfArray(array) {
4555
return spy.printf.apply(spy, array);
4656
}
4757

4858
return {
49-
affirmative: printfArray(["expected %n to " + verbPhrase + action + nonNegatedSuffix].concat(args)),
50-
negative: printfArray(["expected %n to not " + verbPhrase + action].concat(args))
59+
affirmative: function () {
60+
return printfArray(["expected %n to " + verbPhrase + action + nonNegatedSuffix].concat(args));
61+
},
62+
negative: function () {
63+
return printfArray(["expected %n to not " + verbPhrase + action].concat(args));
64+
}
5165
};
5266
}
5367

@@ -60,6 +74,15 @@
6074
});
6175
}
6276

77+
function sinonPropertyAsBooleanMethod(name, action, nonNegatedSuffix) {
78+
utils.addMethod(chai.Assertion.prototype, name, function (arg) {
79+
assertCanWorkWith(this);
80+
81+
var messages = getMessages(this._obj, action, nonNegatedSuffix, false, [timesInWords(arg)]);
82+
this.assert(this._obj[name] === arg, messages.affirmative, messages.negative);
83+
});
84+
}
85+
6386
function createSinonMethodHandler(sinonName, action, nonNegatedSuffix) {
6487
return function () {
6588
assertCanWorkWith(this);
@@ -92,6 +115,7 @@
92115
});
93116

94117
sinonProperty("called", "been called", " at least once, but it was never called");
118+
sinonPropertyAsBooleanMethod("callCount", "been called exactly %1", ", but it was called %c%C");
95119
sinonProperty("calledOnce", "been called exactly once", ", but it was called %c%C");
96120
sinonProperty("calledTwice", "been called exactly twice", ", but it was called %c%C");
97121
sinonProperty("calledThrice", "been called exactly thrice", ", but it was called %c%C");
@@ -101,6 +125,7 @@
101125
sinonMethod("calledOn", "been called with %1 as this", ", but it was called with %t instead");
102126
sinonMethod("calledWith", "been called with arguments %*", "%C");
103127
sinonMethod("calledWithExactly", "been called with exact arguments %*", "%C");
128+
sinonMethod("calledWithMatch", "been called with arguments matching %*", "%C");
104129
sinonMethod("returned", "returned %1");
105130
exceptionalSinonMethod("thrown", "threw", "thrown %1");
106131
}));

‎tests/sinon.js

+3,943-2,343
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.