-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
issues-test.js
234 lines (187 loc) · 7.11 KB
/
issues-test.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
"use strict";
var referee = require("referee");
var sinon = require("../../lib/sinon");
var configureLogError = require("../../lib/sinon/util/core/log_error.js");
var assert = referee.assert;
var refute = referee.refute;
describe("issues", function () {
beforeEach(function () {
this.sandbox = sinon.sandbox.create();
});
afterEach(function () {
this.sandbox.restore();
});
it("#283", function () {
function testSinonFakeTimersWith(interval, ticks) {
var clock = sinon.useFakeTimers();
var spy = sinon.spy();
var id = setInterval(spy, interval);
assert(!spy.calledOnce);
clock.tick(ticks);
assert(spy.callCount === Math.floor(ticks / interval));
clearInterval(id);
clock.restore();
}
testSinonFakeTimersWith(10, 101);
testSinonFakeTimersWith(99, 101);
testSinonFakeTimersWith(100, 200);
testSinonFakeTimersWith(199, 200);
testSinonFakeTimersWith(500, 1001);
testSinonFakeTimersWith(1000, 1001);
});
describe("#458", function () {
if (typeof require("fs").readFileSync !== "undefined") {
describe("on node", function () {
it("stub out fs.readFileSync", function () {
var fs = require("fs");
var testCase = this;
refute.exception(function () {
testCase.sandbox.stub(fs, "readFileSync");
});
});
});
}
});
describe("#624", function () {
it.skip("useFakeTimers should be idempotent", function () {
// Issue #624 shows that useFakeTimers is not idempotent when it comes to
// using Date.now
// This test verifies that it's working, at least for Date.now
var clock;
clock = sinon.useFakeTimers(new Date("2014-12-29").getTime());
assert.equals(clock.now, Date.now());
clock = sinon.useFakeTimers(new Date("2015-12-15").getTime());
assert.equals(clock.now, Date.now());
clock = sinon.useFakeTimers(new Date("2015-1-5").getTime());
assert.equals(clock.now, Date.now());
});
});
describe("#835", function () {
it("logError() throws an exception if the passed err is read-only", function () {
var logError = configureLogError({useImmediateExceptions: true});
// passes
var err = { name: "TestError", message: "this is a proper exception" };
assert.exception(
function () {
logError("#835 test", err);
},
{
name: err.name
}
);
// fails until this issue is fixed
assert.exception(
function () {
logError("#835 test", "this literal string is not a proper exception");
},
{
name: "#835 test"
}
);
});
});
describe("#852 - createStubInstance on intherited constructors", function () {
it("must not throw error", function () {
var A = function () {};
var B = function () {};
B.prototype = Object.create(A.prototype);
B.prototype.constructor = A;
refute.exception(function () {
sinon.createStubInstance(B);
});
});
});
describe("#852(2) - createStubInstance should on same constructor", function () {
it("must be idempotent", function () {
var A = function () {};
refute.exception(function () {
sinon.createStubInstance(A);
sinon.createStubInstance(A);
});
});
});
describe("#950 - first execution of a spy as a method renames that spy", function () {
function bob() {}
// IE 11 does not support the function name property
if (bob.name) {
it("should not rename spies", function () {
var expectedName = "proxy";
var spy = sinon.spy(bob);
assert.equals(spy.name, expectedName);
var obj = { methodName: spy };
assert.equals(spy.name, expectedName);
spy();
assert.equals(spy.name, expectedName);
obj.methodName.call(null);
assert.equals(spy.name, expectedName);
obj.methodName();
assert.equals(spy.name, expectedName);
obj.otherProp = spy;
obj.otherProp();
assert.equals(spy.name, expectedName);
});
}
});
describe("#1026", function () {
it("should stub `watch` method on any Object", function () {
// makes sure that Object.prototype.watch is set back to its old value
function restore(oldWatch) {
if (oldWatch) {
Object.prototype.watch = oldWatch; // eslint-disable-line no-extend-native
} else {
delete Object.prototype.watch;
}
}
try { // eslint-disable-line no-restricted-syntax
var oldWatch = Object.prototype.watch;
if (typeof Object.prototype.watch !== "function") {
Object.prototype.watch = function rolex() {}; // eslint-disable-line no-extend-native
}
var stubbedObject = sinon.stub({
watch: function () {}
});
stubbedObject.watch();
assert.isArray(stubbedObject.watch.args);
} catch (error) {
restore(oldWatch);
throw error;
}
restore(oldWatch);
});
});
describe("#1154", function () {
it("Ensures different matchers will not be tested against each other", function () {
var match = sinon.match;
var stub = sinon.stub;
var readFile = stub();
function endsWith(str, suffix) {
return str.indexOf(suffix) + suffix.length === str.length;
}
function suffixA(fileName) {
return endsWith(fileName, "suffixa");
}
function suffixB(fileName) {
return endsWith(fileName, "suffixb");
}
var argsA = match(suffixA);
var argsB = match(suffixB);
var firstFake = readFile
.withArgs(argsA);
var secondFake = readFile
.withArgs(argsB);
assert(firstFake !== secondFake);
});
});
describe("#1398", function () {
it("Call order takes into account both calledBefore and callCount", function () {
var s1 = sinon.spy();
var s2 = sinon.spy();
s1();
s2();
s1();
assert.exception(function () {
sinon.assert.callOrder(s2, s1, s2);
});
});
});
});