|
0
|
1 |
<html> |
|
|
2 |
<head> |
|
|
3 |
<title>mock tests</title> |
|
|
4 |
<link type="text/css" rel="stylesheet" href="../../../build/logreader/assets/skins/sam/logreader.css" /> |
|
|
5 |
<script type="text/javascript" src="../../../build/yui/yui.js"></script> |
|
|
6 |
</head> |
|
|
7 |
<body class="yui-skin-sam"> |
|
|
8 |
<h1>Mock Tests</h1> |
|
|
9 |
<div id="c"></div> |
|
|
10 |
<script type="text/javascript"> |
|
|
11 |
|
|
|
12 |
YUI({ |
|
|
13 |
base: '../../../build/', |
|
|
14 |
filter: "debug", |
|
|
15 |
logInclude: { TestRunner: true } |
|
|
16 |
}).use('test', 'console', function (Y) { |
|
|
17 |
|
|
|
18 |
Y.namespace("Tests"); |
|
|
19 |
|
|
|
20 |
Y.Tests.Mock = (function(){ |
|
|
21 |
|
|
|
22 |
var Assert = Y.Assert, |
|
|
23 |
ObjectAssert = Y.ObjectAssert; |
|
|
24 |
|
|
|
25 |
//------------------------------------------------------------------------- |
|
|
26 |
// Base Test Suite |
|
|
27 |
//------------------------------------------------------------------------- |
|
|
28 |
|
|
|
29 |
var suite = new Y.Test.Suite("Mock Tests"); |
|
|
30 |
|
|
|
31 |
//------------------------------------------------------------------------- |
|
|
32 |
// Test Case for call count |
|
|
33 |
//------------------------------------------------------------------------- |
|
|
34 |
|
|
|
35 |
suite.add(new Y.Test.Case({ |
|
|
36 |
|
|
|
37 |
name : "Call Count Tests", |
|
|
38 |
|
|
|
39 |
_should: { |
|
|
40 |
fail: { |
|
|
41 |
"Call count should default to 1 and fail": 1, |
|
|
42 |
"Call count set to 1 should fail when method isn't called": 1, |
|
|
43 |
"Call count set to 1 should fail when method is called twice": 1, |
|
|
44 |
"Call count set to 0 should fail when method is called once": 1 |
|
|
45 |
} |
|
|
46 |
}, |
|
|
47 |
|
|
|
48 |
/* |
|
|
49 |
* Tests that leaving off callCount results in a callCount of 1, so |
|
|
50 |
* calling the mock method once should make the test pass. |
|
|
51 |
*/ |
|
|
52 |
"Call count should default to 1 and pass": function(){ |
|
|
53 |
|
|
|
54 |
var mock = Y.Mock(); |
|
|
55 |
Y.Mock.expect(mock, { |
|
|
56 |
method: "method" |
|
|
57 |
}); |
|
|
58 |
|
|
|
59 |
mock.method(); |
|
|
60 |
Y.Mock.verify(mock); |
|
|
61 |
}, |
|
|
62 |
|
|
|
63 |
/* |
|
|
64 |
* Tests that leaving off callCount results in a callCount of 1, so |
|
|
65 |
* not calling the mock method once should make the test fail. |
|
|
66 |
*/ |
|
|
67 |
"Call count should default to 1 and fail": function(){ |
|
|
68 |
|
|
|
69 |
var mock = Y.Mock(); |
|
|
70 |
Y.Mock.expect(mock, { |
|
|
71 |
method: "method" |
|
|
72 |
}); |
|
|
73 |
|
|
|
74 |
Y.Mock.verify(mock); |
|
|
75 |
}, |
|
|
76 |
|
|
|
77 |
/* |
|
|
78 |
* Tests that setting callCount to 1 and |
|
|
79 |
* calling the mock method once should make the test pass. |
|
|
80 |
*/ |
|
|
81 |
"Call count set to 1 should pass when method is called once": function(){ |
|
|
82 |
|
|
|
83 |
var mock = Y.Mock(); |
|
|
84 |
Y.Mock.expect(mock, { |
|
|
85 |
method: "method", |
|
|
86 |
callCount: 1 |
|
|
87 |
}); |
|
|
88 |
|
|
|
89 |
mock.method(); |
|
|
90 |
Y.Mock.verify(mock); |
|
|
91 |
}, |
|
|
92 |
|
|
|
93 |
/* |
|
|
94 |
* Tests that setting callCount to 1 and not |
|
|
95 |
* calling the mock method once should make the test fail. |
|
|
96 |
*/ |
|
|
97 |
"Call count set to 1 should fail when method isn't called": function(){ |
|
|
98 |
|
|
|
99 |
var mock = Y.Mock(); |
|
|
100 |
Y.Mock.expect(mock, { |
|
|
101 |
method: "method", |
|
|
102 |
callCount: 1 |
|
|
103 |
}); |
|
|
104 |
|
|
|
105 |
Y.Mock.verify(mock); |
|
|
106 |
}, |
|
|
107 |
|
|
|
108 |
/* |
|
|
109 |
* Tests that setting callCount to 1 and not |
|
|
110 |
* calling the mock method twice should make the test fail. |
|
|
111 |
*/ |
|
|
112 |
"Call count set to 1 should fail when method is called twice": function(){ |
|
|
113 |
|
|
|
114 |
var mock = Y.Mock(); |
|
|
115 |
Y.Mock.expect(mock, { |
|
|
116 |
method: "method", |
|
|
117 |
callCount: 1 |
|
|
118 |
}); |
|
|
119 |
|
|
|
120 |
mock.method(); |
|
|
121 |
mock.method(); |
|
|
122 |
|
|
|
123 |
Y.Mock.verify(mock); |
|
|
124 |
}, |
|
|
125 |
|
|
|
126 |
/* |
|
|
127 |
* Tests that setting callCount to 0 and |
|
|
128 |
* calling the mock method once should make the test fail. |
|
|
129 |
*/ |
|
|
130 |
"Call count set to 0 should fail when method is called once": function(){ |
|
|
131 |
|
|
|
132 |
var mock = Y.Mock(); |
|
|
133 |
Y.Mock.expect(mock, { |
|
|
134 |
method: "method", |
|
|
135 |
callCount: 0 |
|
|
136 |
}); |
|
|
137 |
|
|
|
138 |
mock.method(); |
|
|
139 |
Y.Mock.verify(mock); |
|
|
140 |
}, |
|
|
141 |
|
|
|
142 |
/* |
|
|
143 |
* Tests that setting callCount to 0 and not |
|
|
144 |
* calling the mock method once should make the test pass. |
|
|
145 |
*/ |
|
|
146 |
"Call count set to 0 should pass when method isn't called": function(){ |
|
|
147 |
|
|
|
148 |
var mock = Y.Mock(); |
|
|
149 |
Y.Mock.expect(mock, { |
|
|
150 |
method: "method", |
|
|
151 |
callCount: 0 |
|
|
152 |
}); |
|
|
153 |
|
|
|
154 |
Y.Mock.verify(mock); |
|
|
155 |
} |
|
|
156 |
|
|
|
157 |
})); |
|
|
158 |
|
|
|
159 |
//------------------------------------------------------------------------- |
|
|
160 |
// Test Case for arguments |
|
|
161 |
//------------------------------------------------------------------------- |
|
|
162 |
|
|
|
163 |
suite.add(new Y.Test.Case({ |
|
|
164 |
|
|
|
165 |
name : "Arguments Tests", |
|
|
166 |
|
|
|
167 |
_should: { |
|
|
168 |
fail: { |
|
|
169 |
"Passing an incorrect number of arguments should make the test fail": 1, |
|
|
170 |
"Passing an inexact argument should make the test fail" : 1, |
|
|
171 |
|
|
|
172 |
"Passing a number to an Boolean argument should make the test fail": 1, |
|
|
173 |
"Passing a string to an Boolean argument should make the test fail": 1, |
|
|
174 |
"Passing a object to an Boolean argument should make the test fail": 1, |
|
|
175 |
"Passing a function to an Boolean argument should make the test fail": 1, |
|
|
176 |
"Passing a null to an Boolean argument should make the test fail": 1, |
|
|
177 |
|
|
|
178 |
"Passing a number to an String argument should make the test fail": 1, |
|
|
179 |
"Passing a boolean to an String argument should make the test fail": 1, |
|
|
180 |
"Passing a object to an String argument should make the test fail": 1, |
|
|
181 |
"Passing a function to an String argument should make the test fail": 1, |
|
|
182 |
"Passing a null to an String argument should make the test fail": 1, |
|
|
183 |
|
|
|
184 |
"Passing a string to an Number argument should make the test fail": 1, |
|
|
185 |
"Passing a boolean to an Number argument should make the test fail": 1, |
|
|
186 |
"Passing a object to an Number argument should make the test fail": 1, |
|
|
187 |
"Passing a function to an Number argument should make the test fail": 1, |
|
|
188 |
"Passing a null to an Number argument should make the test fail": 1, |
|
|
189 |
|
|
|
190 |
"Passing a string to an Object argument should make the test fail": 1, |
|
|
191 |
"Passing a boolean to an Object argument should make the test fail": 1, |
|
|
192 |
"Passing a number to an Object argument should make the test fail": 1, |
|
|
193 |
"Passing a null to an Object argument should make the test fail": 1, |
|
|
194 |
|
|
|
195 |
"Passing a string to an Function argument should make the test fail": 1, |
|
|
196 |
"Passing a boolean to an Function argument should make the test fail": 1, |
|
|
197 |
"Passing a number to an Function argument should make the test fail": 1, |
|
|
198 |
"Passing a object to an Function argument should make the test fail": 1, |
|
|
199 |
"Passing a null to an Function argument should make the test fail": 1 |
|
|
200 |
|
|
|
201 |
|
|
|
202 |
} |
|
|
203 |
}, |
|
|
204 |
|
|
|
205 |
/* |
|
|
206 |
* Tests that when the number of arguments is verified, the test passes. |
|
|
207 |
*/ |
|
|
208 |
"Passing correct number of arguments should make the test pass": function(){ |
|
|
209 |
|
|
|
210 |
var mock = Y.Mock(); |
|
|
211 |
Y.Mock.expect(mock, { |
|
|
212 |
method: "method", |
|
|
213 |
args: [ Y.Mock.Value.Any ] |
|
|
214 |
}); |
|
|
215 |
|
|
|
216 |
mock.method(1); |
|
|
217 |
Y.Mock.verify(mock); |
|
|
218 |
}, |
|
|
219 |
|
|
|
220 |
/* |
|
|
221 |
* Tests that when the number of arguments is not verified, the test fails. |
|
|
222 |
*/ |
|
|
223 |
"Passing an incorrect number of arguments should make the test fail": function(){ |
|
|
224 |
|
|
|
225 |
var mock = Y.Mock(); |
|
|
226 |
Y.Mock.expect(mock, { |
|
|
227 |
method: "method", |
|
|
228 |
args: [ Y.Mock.Value.Any ] |
|
|
229 |
}); |
|
|
230 |
|
|
|
231 |
mock.method(1, 2); |
|
|
232 |
Y.Mock.verify(mock); |
|
|
233 |
}, |
|
|
234 |
|
|
|
235 |
/* |
|
|
236 |
* Tests that passing the exactly specified argument causes the test to pass. |
|
|
237 |
*/ |
|
|
238 |
"Passing the exact argument should make the test pass": function(){ |
|
|
239 |
|
|
|
240 |
var arg = {}; |
|
|
241 |
var mock = Y.Mock(); |
|
|
242 |
Y.Mock.expect(mock, { |
|
|
243 |
method: "method", |
|
|
244 |
args: [ arg ] |
|
|
245 |
}); |
|
|
246 |
|
|
|
247 |
mock.method(arg); |
|
|
248 |
Y.Mock.verify(mock); |
|
|
249 |
}, |
|
|
250 |
|
|
|
251 |
/* |
|
|
252 |
* Tests that passing an argument that isn't exactly specified argument causes the test to fail. |
|
|
253 |
*/ |
|
|
254 |
"Passing an inexact argument should make the test fail": function(){ |
|
|
255 |
|
|
|
256 |
var arg = {}; |
|
|
257 |
var mock = Y.Mock(); |
|
|
258 |
Y.Mock.expect(mock, { |
|
|
259 |
method: "method", |
|
|
260 |
args: [ arg ] |
|
|
261 |
}); |
|
|
262 |
|
|
|
263 |
mock.method({}); |
|
|
264 |
Y.Mock.verify(mock); |
|
|
265 |
}, |
|
|
266 |
|
|
|
267 |
//Y.Mock.Value.Any tests -------------------------------------- |
|
|
268 |
|
|
|
269 |
/* |
|
|
270 |
* Tests that passing a number to an argument specified as Y.Mock.Value.Any |
|
|
271 |
* results cause the test to pass. |
|
|
272 |
*/ |
|
|
273 |
"Passing a number to an Any argument should make the test pass": function(){ |
|
|
274 |
|
|
|
275 |
var mock = Y.Mock(); |
|
|
276 |
Y.Mock.expect(mock, { |
|
|
277 |
method: "method", |
|
|
278 |
args: [ Y.Mock.Value.Any ] |
|
|
279 |
}); |
|
|
280 |
|
|
|
281 |
mock.method(1); |
|
|
282 |
Y.Mock.verify(mock); |
|
|
283 |
}, |
|
|
284 |
|
|
|
285 |
/* |
|
|
286 |
* Tests that passing a boolean to an argument specified as Y.Mock.Value.Any |
|
|
287 |
* results cause the test to pass. |
|
|
288 |
*/ |
|
|
289 |
"Passing a boolean to an Any argument should make the test pass": function(){ |
|
|
290 |
|
|
|
291 |
var mock = Y.Mock(); |
|
|
292 |
Y.Mock.expect(mock, { |
|
|
293 |
method: "method", |
|
|
294 |
args: [ Y.Mock.Value.Any ] |
|
|
295 |
}); |
|
|
296 |
|
|
|
297 |
mock.method(true); |
|
|
298 |
Y.Mock.verify(mock); |
|
|
299 |
}, |
|
|
300 |
|
|
|
301 |
/* |
|
|
302 |
* Tests that passing a string to an argument specified as Y.Mock.Value.Any |
|
|
303 |
* results cause the test to pass. |
|
|
304 |
*/ |
|
|
305 |
"Passing a string to an Any argument should make the test pass": function(){ |
|
|
306 |
|
|
|
307 |
var mock = Y.Mock(); |
|
|
308 |
Y.Mock.expect(mock, { |
|
|
309 |
method: "method", |
|
|
310 |
args: [ Y.Mock.Value.Any ] |
|
|
311 |
}); |
|
|
312 |
|
|
|
313 |
mock.method(""); |
|
|
314 |
Y.Mock.verify(mock); |
|
|
315 |
}, |
|
|
316 |
|
|
|
317 |
/* |
|
|
318 |
* Tests that passing an object to an argument specified as Y.Mock.Value.Any |
|
|
319 |
* results cause the test to pass. |
|
|
320 |
*/ |
|
|
321 |
"Passing a object to an Any argument should make the test pass": function(){ |
|
|
322 |
|
|
|
323 |
var mock = Y.Mock(); |
|
|
324 |
Y.Mock.expect(mock, { |
|
|
325 |
method: "method", |
|
|
326 |
args: [ Y.Mock.Value.Any ] |
|
|
327 |
}); |
|
|
328 |
|
|
|
329 |
mock.method({}); |
|
|
330 |
Y.Mock.verify(mock); |
|
|
331 |
}, |
|
|
332 |
|
|
|
333 |
/* |
|
|
334 |
* Tests that passing a function to an argument specified as Y.Mock.Value.Any |
|
|
335 |
* results cause the test to pass. |
|
|
336 |
*/ |
|
|
337 |
"Passing a function to an Any argument should make the test pass": function(){ |
|
|
338 |
|
|
|
339 |
var mock = Y.Mock(); |
|
|
340 |
Y.Mock.expect(mock, { |
|
|
341 |
method: "method", |
|
|
342 |
args: [ Y.Mock.Value.Any ] |
|
|
343 |
}); |
|
|
344 |
|
|
|
345 |
mock.method(function(){}); |
|
|
346 |
Y.Mock.verify(mock); |
|
|
347 |
}, |
|
|
348 |
|
|
|
349 |
/* |
|
|
350 |
* Tests that passing a null to an argument specified as Y.Mock.Value.Any |
|
|
351 |
* results cause the test to pass. |
|
|
352 |
*/ |
|
|
353 |
"Passing a null to an Any argument should make the test pass": function(){ |
|
|
354 |
|
|
|
355 |
var mock = Y.Mock(); |
|
|
356 |
Y.Mock.expect(mock, { |
|
|
357 |
method: "method", |
|
|
358 |
args: [ Y.Mock.Value.Any ] |
|
|
359 |
}); |
|
|
360 |
|
|
|
361 |
mock.method(null); |
|
|
362 |
Y.Mock.verify(mock); |
|
|
363 |
}, |
|
|
364 |
|
|
|
365 |
//Y.Mock.Value.Boolean tests -------------------------------------- |
|
|
366 |
|
|
|
367 |
/* |
|
|
368 |
* Tests that passing a number to an argument specified as Y.Mock.Value.Boolean |
|
|
369 |
* results cause the test to fail. |
|
|
370 |
*/ |
|
|
371 |
"Passing a number to an Boolean argument should make the test fail": function(){ |
|
|
372 |
|
|
|
373 |
var mock = Y.Mock(); |
|
|
374 |
Y.Mock.expect(mock, { |
|
|
375 |
method: "method", |
|
|
376 |
args: [ Y.Mock.Value.Boolean ] |
|
|
377 |
}); |
|
|
378 |
|
|
|
379 |
mock.method(1); |
|
|
380 |
Y.Mock.verify(mock); |
|
|
381 |
}, |
|
|
382 |
|
|
|
383 |
/* |
|
|
384 |
* Tests that passing a boolean to an argument specified as Y.Mock.Value.Boolean |
|
|
385 |
* results cause the test to pass. |
|
|
386 |
*/ |
|
|
387 |
"Passing a boolean to an Boolean argument should make the test pass": function(){ |
|
|
388 |
|
|
|
389 |
var mock = Y.Mock(); |
|
|
390 |
Y.Mock.expect(mock, { |
|
|
391 |
method: "method", |
|
|
392 |
args: [ Y.Mock.Value.Boolean ] |
|
|
393 |
}); |
|
|
394 |
|
|
|
395 |
mock.method(true); |
|
|
396 |
Y.Mock.verify(mock); |
|
|
397 |
}, |
|
|
398 |
|
|
|
399 |
/* |
|
|
400 |
* Tests that passing a string to an argument specified as Y.Mock.Value.Boolean |
|
|
401 |
* results cause the test to fail. |
|
|
402 |
*/ |
|
|
403 |
"Passing a string to an Boolean argument should make the test fail": function(){ |
|
|
404 |
|
|
|
405 |
var mock = Y.Mock(); |
|
|
406 |
Y.Mock.expect(mock, { |
|
|
407 |
method: "method", |
|
|
408 |
args: [ Y.Mock.Value.Boolean ] |
|
|
409 |
}); |
|
|
410 |
|
|
|
411 |
mock.method(""); |
|
|
412 |
Y.Mock.verify(mock); |
|
|
413 |
}, |
|
|
414 |
|
|
|
415 |
/* |
|
|
416 |
* Tests that passing an object to an argument specified as Y.Mock.Value.Boolean |
|
|
417 |
* results cause the test to fail. |
|
|
418 |
*/ |
|
|
419 |
"Passing a object to an Boolean argument should make the test fail": function(){ |
|
|
420 |
|
|
|
421 |
var mock = Y.Mock(); |
|
|
422 |
Y.Mock.expect(mock, { |
|
|
423 |
method: "method", |
|
|
424 |
args: [ Y.Mock.Value.Boolean ] |
|
|
425 |
}); |
|
|
426 |
|
|
|
427 |
mock.method({}); |
|
|
428 |
Y.Mock.verify(mock); |
|
|
429 |
}, |
|
|
430 |
|
|
|
431 |
/* |
|
|
432 |
* Tests that passing a function to an argument specified as Y.Mock.Value.Boolean |
|
|
433 |
* results cause the test to fail. |
|
|
434 |
*/ |
|
|
435 |
"Passing a function to an Boolean argument should make the test fail": function(){ |
|
|
436 |
|
|
|
437 |
var mock = Y.Mock(); |
|
|
438 |
Y.Mock.expect(mock, { |
|
|
439 |
method: "method", |
|
|
440 |
args: [ Y.Mock.Value.Boolean ] |
|
|
441 |
}); |
|
|
442 |
|
|
|
443 |
mock.method(function(){}); |
|
|
444 |
Y.Mock.verify(mock); |
|
|
445 |
}, |
|
|
446 |
|
|
|
447 |
/* |
|
|
448 |
* Tests that passing a null to an argument specified as Y.Mock.Value.Boolean |
|
|
449 |
* results cause the test to fail. |
|
|
450 |
*/ |
|
|
451 |
"Passing a null to an Boolean argument should make the test fail": function(){ |
|
|
452 |
|
|
|
453 |
var mock = Y.Mock(); |
|
|
454 |
Y.Mock.expect(mock, { |
|
|
455 |
method: "method", |
|
|
456 |
args: [ Y.Mock.Value.Boolean ] |
|
|
457 |
}); |
|
|
458 |
|
|
|
459 |
mock.method(null); |
|
|
460 |
Y.Mock.verify(mock); |
|
|
461 |
}, |
|
|
462 |
|
|
|
463 |
//Y.Mock.Value.String tests -------------------------------------- |
|
|
464 |
|
|
|
465 |
/* |
|
|
466 |
* Tests that passing a number to an argument specified as Y.Mock.Value.String |
|
|
467 |
* results cause the test to fail. |
|
|
468 |
*/ |
|
|
469 |
"Passing a number to an String argument should make the test fail": function(){ |
|
|
470 |
|
|
|
471 |
var mock = Y.Mock(); |
|
|
472 |
Y.Mock.expect(mock, { |
|
|
473 |
method: "method", |
|
|
474 |
args: [ Y.Mock.Value.String ] |
|
|
475 |
}); |
|
|
476 |
|
|
|
477 |
mock.method(1); |
|
|
478 |
Y.Mock.verify(mock); |
|
|
479 |
}, |
|
|
480 |
|
|
|
481 |
/* |
|
|
482 |
* Tests that passing a boolean to an argument specified as Y.Mock.Value.String |
|
|
483 |
* results cause the test to fail. |
|
|
484 |
*/ |
|
|
485 |
"Passing a boolean to an String argument should make the test fail": function(){ |
|
|
486 |
|
|
|
487 |
var mock = Y.Mock(); |
|
|
488 |
Y.Mock.expect(mock, { |
|
|
489 |
method: "method", |
|
|
490 |
args: [ Y.Mock.Value.String ] |
|
|
491 |
}); |
|
|
492 |
|
|
|
493 |
mock.method(true); |
|
|
494 |
Y.Mock.verify(mock); |
|
|
495 |
}, |
|
|
496 |
|
|
|
497 |
/* |
|
|
498 |
* Tests that passing a string to an argument specified as Y.Mock.Value.String |
|
|
499 |
* results cause the test to pass. |
|
|
500 |
*/ |
|
|
501 |
"Passing a string to an String argument should make the test pass": function(){ |
|
|
502 |
|
|
|
503 |
var mock = Y.Mock(); |
|
|
504 |
Y.Mock.expect(mock, { |
|
|
505 |
method: "method", |
|
|
506 |
args: [ Y.Mock.Value.String ] |
|
|
507 |
}); |
|
|
508 |
|
|
|
509 |
mock.method(""); |
|
|
510 |
Y.Mock.verify(mock); |
|
|
511 |
}, |
|
|
512 |
|
|
|
513 |
/* |
|
|
514 |
* Tests that passing an object to an argument specified as Y.Mock.Value.String |
|
|
515 |
* results cause the test to fail. |
|
|
516 |
*/ |
|
|
517 |
"Passing a object to an String argument should make the test fail": function(){ |
|
|
518 |
|
|
|
519 |
var mock = Y.Mock(); |
|
|
520 |
Y.Mock.expect(mock, { |
|
|
521 |
method: "method", |
|
|
522 |
args: [ Y.Mock.Value.String ] |
|
|
523 |
}); |
|
|
524 |
|
|
|
525 |
mock.method({}); |
|
|
526 |
Y.Mock.verify(mock); |
|
|
527 |
}, |
|
|
528 |
|
|
|
529 |
/* |
|
|
530 |
* Tests that passing a function to an argument specified as Y.Mock.Value.String |
|
|
531 |
* results cause the test to fail. |
|
|
532 |
*/ |
|
|
533 |
"Passing a function to an String argument should make the test fail": function(){ |
|
|
534 |
|
|
|
535 |
var mock = Y.Mock(); |
|
|
536 |
Y.Mock.expect(mock, { |
|
|
537 |
method: "method", |
|
|
538 |
args: [ Y.Mock.Value.String ] |
|
|
539 |
}); |
|
|
540 |
|
|
|
541 |
mock.method(function(){}); |
|
|
542 |
Y.Mock.verify(mock); |
|
|
543 |
}, |
|
|
544 |
|
|
|
545 |
/* |
|
|
546 |
* Tests that passing a null to an argument specified as Y.Mock.Value.String |
|
|
547 |
* results cause the test to fail. |
|
|
548 |
*/ |
|
|
549 |
"Passing a null to an String argument should make the test fail": function(){ |
|
|
550 |
|
|
|
551 |
var mock = Y.Mock(); |
|
|
552 |
Y.Mock.expect(mock, { |
|
|
553 |
method: "method", |
|
|
554 |
args: [ Y.Mock.Value.String ] |
|
|
555 |
}); |
|
|
556 |
|
|
|
557 |
mock.method(null); |
|
|
558 |
Y.Mock.verify(mock); |
|
|
559 |
}, |
|
|
560 |
|
|
|
561 |
//Y.Mock.Value.Number tests -------------------------------------- |
|
|
562 |
|
|
|
563 |
/* |
|
|
564 |
* Tests that passing a number to an argument specified as Y.Mock.Value.Number |
|
|
565 |
* results cause the test to pass. |
|
|
566 |
*/ |
|
|
567 |
"Passing a number to an Number argument should make the test pass": function(){ |
|
|
568 |
|
|
|
569 |
var mock = Y.Mock(); |
|
|
570 |
Y.Mock.expect(mock, { |
|
|
571 |
method: "method", |
|
|
572 |
args: [ Y.Mock.Value.Number ] |
|
|
573 |
}); |
|
|
574 |
|
|
|
575 |
mock.method(1); |
|
|
576 |
Y.Mock.verify(mock); |
|
|
577 |
}, |
|
|
578 |
|
|
|
579 |
/* |
|
|
580 |
* Tests that passing a boolean to an argument specified as Y.Mock.Value.Number |
|
|
581 |
* results cause the test to fail. |
|
|
582 |
*/ |
|
|
583 |
"Passing a boolean to an Number argument should make the test fail": function(){ |
|
|
584 |
|
|
|
585 |
var mock = Y.Mock(); |
|
|
586 |
Y.Mock.expect(mock, { |
|
|
587 |
method: "method", |
|
|
588 |
args: [ Y.Mock.Value.Number ] |
|
|
589 |
}); |
|
|
590 |
|
|
|
591 |
mock.method(true); |
|
|
592 |
Y.Mock.verify(mock); |
|
|
593 |
}, |
|
|
594 |
|
|
|
595 |
/* |
|
|
596 |
* Tests that passing a string to an argument specified as Y.Mock.Value.Number |
|
|
597 |
* results cause the test to fail. |
|
|
598 |
*/ |
|
|
599 |
"Passing a string to an Number argument should make the test fail": function(){ |
|
|
600 |
|
|
|
601 |
var mock = Y.Mock(); |
|
|
602 |
Y.Mock.expect(mock, { |
|
|
603 |
method: "method", |
|
|
604 |
args: [ Y.Mock.Value.Number ] |
|
|
605 |
}); |
|
|
606 |
|
|
|
607 |
mock.method(""); |
|
|
608 |
Y.Mock.verify(mock); |
|
|
609 |
}, |
|
|
610 |
|
|
|
611 |
/* |
|
|
612 |
* Tests that passing an object to an argument specified as Y.Mock.Value.Number |
|
|
613 |
* results cause the test to fail. |
|
|
614 |
*/ |
|
|
615 |
"Passing a object to an Number argument should make the test fail": function(){ |
|
|
616 |
|
|
|
617 |
var mock = Y.Mock(); |
|
|
618 |
Y.Mock.expect(mock, { |
|
|
619 |
method: "method", |
|
|
620 |
args: [ Y.Mock.Value.Number ] |
|
|
621 |
}); |
|
|
622 |
|
|
|
623 |
mock.method({}); |
|
|
624 |
Y.Mock.verify(mock); |
|
|
625 |
}, |
|
|
626 |
|
|
|
627 |
/* |
|
|
628 |
* Tests that passing a function to an argument specified as Y.Mock.Value.Number |
|
|
629 |
* results cause the test to fail. |
|
|
630 |
*/ |
|
|
631 |
"Passing a function to an Number argument should make the test fail": function(){ |
|
|
632 |
|
|
|
633 |
var mock = Y.Mock(); |
|
|
634 |
Y.Mock.expect(mock, { |
|
|
635 |
method: "method", |
|
|
636 |
args: [ Y.Mock.Value.Number ] |
|
|
637 |
}); |
|
|
638 |
|
|
|
639 |
mock.method(function(){}); |
|
|
640 |
Y.Mock.verify(mock); |
|
|
641 |
}, |
|
|
642 |
|
|
|
643 |
/* |
|
|
644 |
* Tests that passing a null to an argument specified as Y.Mock.Value.Number |
|
|
645 |
* results cause the test to fail. |
|
|
646 |
*/ |
|
|
647 |
"Passing a null to an Number argument should make the test fail": function(){ |
|
|
648 |
|
|
|
649 |
var mock = Y.Mock(); |
|
|
650 |
Y.Mock.expect(mock, { |
|
|
651 |
method: "method", |
|
|
652 |
args: [ Y.Mock.Value.Number ] |
|
|
653 |
}); |
|
|
654 |
|
|
|
655 |
mock.method(null); |
|
|
656 |
Y.Mock.verify(mock); |
|
|
657 |
}, |
|
|
658 |
|
|
|
659 |
//Y.Mock.Value.Function tests -------------------------------------- |
|
|
660 |
|
|
|
661 |
/* |
|
|
662 |
* Tests that passing a number to an argument specified as Y.Mock.Value.Function |
|
|
663 |
* results cause the test to fail. |
|
|
664 |
*/ |
|
|
665 |
"Passing a number to an Function argument should make the test fail": function(){ |
|
|
666 |
|
|
|
667 |
var mock = Y.Mock(); |
|
|
668 |
Y.Mock.expect(mock, { |
|
|
669 |
method: "method", |
|
|
670 |
args: [ Y.Mock.Value.Function ] |
|
|
671 |
}); |
|
|
672 |
|
|
|
673 |
mock.method(1); |
|
|
674 |
Y.Mock.verify(mock); |
|
|
675 |
}, |
|
|
676 |
|
|
|
677 |
/* |
|
|
678 |
* Tests that passing a boolean to an argument specified as Y.Mock.Value.Function |
|
|
679 |
* results cause the test to fail. |
|
|
680 |
*/ |
|
|
681 |
"Passing a boolean to an Function argument should make the test fail": function(){ |
|
|
682 |
|
|
|
683 |
var mock = Y.Mock(); |
|
|
684 |
Y.Mock.expect(mock, { |
|
|
685 |
method: "method", |
|
|
686 |
args: [ Y.Mock.Value.Function ] |
|
|
687 |
}); |
|
|
688 |
|
|
|
689 |
mock.method(true); |
|
|
690 |
Y.Mock.verify(mock); |
|
|
691 |
}, |
|
|
692 |
|
|
|
693 |
/* |
|
|
694 |
* Tests that passing a string to an argument specified as Y.Mock.Value.Function |
|
|
695 |
* results cause the test to fail. |
|
|
696 |
*/ |
|
|
697 |
"Passing a string to an Function argument should make the test fail": function(){ |
|
|
698 |
|
|
|
699 |
var mock = Y.Mock(); |
|
|
700 |
Y.Mock.expect(mock, { |
|
|
701 |
method: "method", |
|
|
702 |
args: [ Y.Mock.Value.Function ] |
|
|
703 |
}); |
|
|
704 |
|
|
|
705 |
mock.method(""); |
|
|
706 |
Y.Mock.verify(mock); |
|
|
707 |
}, |
|
|
708 |
|
|
|
709 |
/* |
|
|
710 |
* Tests that passing an object to an argument specified as Y.Mock.Value.Function |
|
|
711 |
* results cause the test to fail. |
|
|
712 |
*/ |
|
|
713 |
"Passing a object to an Function argument should make the test fail": function(){ |
|
|
714 |
|
|
|
715 |
var mock = Y.Mock(); |
|
|
716 |
Y.Mock.expect(mock, { |
|
|
717 |
method: "method", |
|
|
718 |
args: [ Y.Mock.Value.Function ] |
|
|
719 |
}); |
|
|
720 |
|
|
|
721 |
mock.method({}); |
|
|
722 |
Y.Mock.verify(mock); |
|
|
723 |
}, |
|
|
724 |
|
|
|
725 |
/* |
|
|
726 |
* Tests that passing a function to an argument specified as Y.Mock.Value.Function |
|
|
727 |
* results cause the test to pass. |
|
|
728 |
*/ |
|
|
729 |
"Passing a function to an Function argument should make the test pass": function(){ |
|
|
730 |
|
|
|
731 |
var mock = Y.Mock(); |
|
|
732 |
Y.Mock.expect(mock, { |
|
|
733 |
method: "method", |
|
|
734 |
args: [ Y.Mock.Value.Function ] |
|
|
735 |
}); |
|
|
736 |
|
|
|
737 |
mock.method(function(){}); |
|
|
738 |
Y.Mock.verify(mock); |
|
|
739 |
}, |
|
|
740 |
|
|
|
741 |
/* |
|
|
742 |
* Tests that passing a null to an argument specified as Y.Mock.Value.Function |
|
|
743 |
* results cause the test to fail. |
|
|
744 |
*/ |
|
|
745 |
"Passing a null to an Function argument should make the test fail": function(){ |
|
|
746 |
|
|
|
747 |
var mock = Y.Mock(); |
|
|
748 |
Y.Mock.expect(mock, { |
|
|
749 |
method: "method", |
|
|
750 |
args: [ Y.Mock.Value.Function ] |
|
|
751 |
}); |
|
|
752 |
|
|
|
753 |
mock.method(null); |
|
|
754 |
Y.Mock.verify(mock); |
|
|
755 |
}, |
|
|
756 |
|
|
|
757 |
//Y.Mock.Value.Object tests -------------------------------------- |
|
|
758 |
|
|
|
759 |
/* |
|
|
760 |
* Tests that passing a number to an argument specified as Y.Mock.Value.Object |
|
|
761 |
* results cause the test to fail. |
|
|
762 |
*/ |
|
|
763 |
"Passing a number to an Object argument should make the test fail": function(){ |
|
|
764 |
|
|
|
765 |
var mock = Y.Mock(); |
|
|
766 |
Y.Mock.expect(mock, { |
|
|
767 |
method: "method", |
|
|
768 |
args: [ Y.Mock.Value.Object ] |
|
|
769 |
}); |
|
|
770 |
|
|
|
771 |
mock.method(1); |
|
|
772 |
Y.Mock.verify(mock); |
|
|
773 |
}, |
|
|
774 |
|
|
|
775 |
/* |
|
|
776 |
* Tests that passing a boolean to an argument specified as Y.Mock.Value.Object |
|
|
777 |
* results cause the test to fail. |
|
|
778 |
*/ |
|
|
779 |
"Passing a boolean to an Object argument should make the test fail": function(){ |
|
|
780 |
|
|
|
781 |
var mock = Y.Mock(); |
|
|
782 |
Y.Mock.expect(mock, { |
|
|
783 |
method: "method", |
|
|
784 |
args: [ Y.Mock.Value.Object ] |
|
|
785 |
}); |
|
|
786 |
|
|
|
787 |
mock.method(true); |
|
|
788 |
Y.Mock.verify(mock); |
|
|
789 |
}, |
|
|
790 |
|
|
|
791 |
/* |
|
|
792 |
* Tests that passing a string to an argument specified as Y.Mock.Value.Object |
|
|
793 |
* results cause the test to fail. |
|
|
794 |
*/ |
|
|
795 |
"Passing a string to an Object argument should make the test fail": function(){ |
|
|
796 |
|
|
|
797 |
var mock = Y.Mock(); |
|
|
798 |
Y.Mock.expect(mock, { |
|
|
799 |
method: "method", |
|
|
800 |
args: [ Y.Mock.Value.Object ] |
|
|
801 |
}); |
|
|
802 |
|
|
|
803 |
mock.method(""); |
|
|
804 |
Y.Mock.verify(mock); |
|
|
805 |
}, |
|
|
806 |
|
|
|
807 |
/* |
|
|
808 |
* Tests that passing an object to an argument specified as Y.Mock.Value.Object |
|
|
809 |
* results cause the test to pass. |
|
|
810 |
*/ |
|
|
811 |
"Passing a object to an Object argument should make the test pass": function(){ |
|
|
812 |
|
|
|
813 |
var mock = Y.Mock(); |
|
|
814 |
Y.Mock.expect(mock, { |
|
|
815 |
method: "method", |
|
|
816 |
args: [ Y.Mock.Value.Object ] |
|
|
817 |
}); |
|
|
818 |
|
|
|
819 |
mock.method({}); |
|
|
820 |
Y.Mock.verify(mock); |
|
|
821 |
}, |
|
|
822 |
|
|
|
823 |
/* |
|
|
824 |
* Tests that passing a function to an argument specified as Y.Mock.Value.Object |
|
|
825 |
* results cause the test to pass. |
|
|
826 |
*/ |
|
|
827 |
"Passing a function to an Object argument should make the test pass": function(){ |
|
|
828 |
|
|
|
829 |
var mock = Y.Mock(); |
|
|
830 |
Y.Mock.expect(mock, { |
|
|
831 |
method: "method", |
|
|
832 |
args: [ Y.Mock.Value.Object ] |
|
|
833 |
}); |
|
|
834 |
|
|
|
835 |
mock.method(function(){}); |
|
|
836 |
Y.Mock.verify(mock); |
|
|
837 |
}, |
|
|
838 |
|
|
|
839 |
/* |
|
|
840 |
* Tests that passing a null to an argument specified as Y.Mock.Value.Object |
|
|
841 |
* results cause the test to fail. |
|
|
842 |
*/ |
|
|
843 |
"Passing a null to an Object argument should make the test fail": function(){ |
|
|
844 |
|
|
|
845 |
var mock = Y.Mock(); |
|
|
846 |
Y.Mock.expect(mock, { |
|
|
847 |
method: "method", |
|
|
848 |
args: [ Y.Mock.Value.Object ] |
|
|
849 |
}); |
|
|
850 |
|
|
|
851 |
mock.method(null); |
|
|
852 |
Y.Mock.verify(mock); |
|
|
853 |
} |
|
|
854 |
})); |
|
|
855 |
|
|
|
856 |
//------------------------------------------------------------------------- |
|
|
857 |
// Test Case for asynchronous mock calls |
|
|
858 |
//------------------------------------------------------------------------- |
|
|
859 |
|
|
|
860 |
suite.add(new Y.Test.Case({ |
|
|
861 |
|
|
|
862 |
name : "Asynchronous Tests", |
|
|
863 |
|
|
|
864 |
_should: { |
|
|
865 |
|
|
|
866 |
fail: { |
|
|
867 |
"A mock method called asynchronously shouldn't cause an error": 1 |
|
|
868 |
} |
|
|
869 |
}, |
|
|
870 |
|
|
|
871 |
/* |
|
|
872 |
* Tests that when a mock method is called asynchronously, either via |
|
|
873 |
* timeout or XHR callback, that its error is properly handled and |
|
|
874 |
* the failure is logged to the test. |
|
|
875 |
*/ |
|
|
876 |
"A mock method called asynchronously shouldn't cause an error": function(){ |
|
|
877 |
|
|
|
878 |
var mock = Y.Mock(); |
|
|
879 |
Y.Mock.expect(mock, { |
|
|
880 |
method: "method", |
|
|
881 |
args: [ Y.Mock.Value.String ] |
|
|
882 |
}); |
|
|
883 |
|
|
|
884 |
setTimeout(function(){ |
|
|
885 |
mock.method(null); |
|
|
886 |
}, 250); |
|
|
887 |
|
|
|
888 |
this.wait(function(){ |
|
|
889 |
Y.Mock.verify(mock); |
|
|
890 |
}, 500); |
|
|
891 |
} |
|
|
892 |
|
|
|
893 |
})); |
|
|
894 |
|
|
|
895 |
|
|
|
896 |
//return it |
|
|
897 |
return suite; |
|
|
898 |
|
|
|
899 |
})(); |
|
|
900 |
|
|
|
901 |
|
|
|
902 |
var r = new Y.Console({ |
|
|
903 |
verbose : true, |
|
|
904 |
//consoleLimit : 10, |
|
|
905 |
newestOnTop : false |
|
|
906 |
}); |
|
|
907 |
|
|
|
908 |
r.render('#c'); |
|
|
909 |
|
|
|
910 |
|
|
|
911 |
//add to the testrunner and run |
|
|
912 |
Y.Test.Runner.add(Y.Tests.Mock); |
|
|
913 |
Y.Test.Runner.run(); |
|
|
914 |
|
|
|
915 |
/*if (parent && parent != window) { |
|
|
916 |
YAHOO.tool.TestManager.load(); |
|
|
917 |
} else { |
|
|
918 |
YAHOO.tool.TestRunner.run(); |
|
|
919 |
}*/ |
|
|
920 |
|
|
|
921 |
}); |
|
|
922 |
|
|
|
923 |
|
|
|
924 |
</script> |
|
|
925 |
</body> |
|
|
926 |
</html> |