This repository has been archived by the owner on Feb 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_helper.js
82 lines (71 loc) · 1.82 KB
/
test_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var spies;
var stubs;
var promiseStub;
var eventStub;
eventStub = {
preventDefault: sinon.stub(),
stopPropagation: sinon.stub(),
target: sinon.stub(),
keyCode: 13 // Send enter keyCode by default
};
promiseStub = sinon.stub();
promiseStub.abort = function() {};
promiseStub.fail = function() {};
promiseStub.done = function() {};
promiseStub.always = function() {};
promiseStub.success = function() {};
promiseStub.error = function() {};
promiseStub.then = function() {};
sinon.stub(promiseStub, "abort").returns(promiseStub);
sinon.stub(promiseStub, "fail").returns(promiseStub);
sinon.stub(promiseStub, "done").returns(promiseStub);
sinon.stub(promiseStub, "always").returns(promiseStub);
sinon.stub(promiseStub, "success").returns(promiseStub);
sinon.stub(promiseStub, "error").returns(promiseStub);
sinon.stub(promiseStub, "then").returns(promiseStub);
function spyOn(object, method) {
var spy = sinon.spy(object, method);
spies.push(spy);
return spy;
}
function stub(object, method, retVal) {
var stub = sinon.stub(object, method).returns(retVal);
stubs.push(stub);
return stub;
}
var TestHelper = {
spyOn: function(object, method) {
var spy = sinon.spy(object, method);
spies.push(spy);
return spy;
},
stub: function(object, method, retVal) {
var stub = sinon.stub(object, method).returns(retVal);
stubs.push(stub);
return stub;
},
click: function(el){
var ev = document.createEvent("MouseEvent");
ev.initMouseEvent(
"click",
true, true,
window, null,
0, 0, 0, 0,
false, false, false, false,
0, null
);
el.dispatchEvent(ev);
}
};
beforeEach(function() {
spies = [];
stubs = [];
});
afterEach(function() {
spies.forEach(function(spy) {
spy.restore();
});
stubs.forEach(function(stub) {
stub.restore();
});
});