|
23 | 23 |
|
24 | 24 |
|
25 | 25 | /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ |
26 | | -/*global jasmine, define, describe, beforeEach, it, expect */ |
| 26 | +/*global jasmine, define, describe, beforeEach, it, expect, spyOn */ |
27 | 27 |
|
28 | 28 | define(function (require, exports, module) { |
29 | 29 | "use strict"; |
@@ -429,5 +429,27 @@ define(function (require, exports, module) { |
429 | 429 | expect(fn1).toHaveBeenCalled(); |
430 | 430 | expect(fn2).toHaveBeenCalled(); |
431 | 431 | }); |
| 432 | + |
| 433 | + |
| 434 | + it("on() should print warnings when too many listeners attached", function () { |
| 435 | + function makeStubListener() { // avoids JSLint "don't make functions in a loop" complaint |
| 436 | + return function () {}; |
| 437 | + } |
| 438 | + |
| 439 | + spyOn(console, "error"); |
| 440 | + var i; |
| 441 | + for (i = 0; i < 15; i++) { |
| 442 | + dispatcher.on("foo", makeStubListener()); |
| 443 | + } |
| 444 | + expect(console.error).not.toHaveBeenCalled(); |
| 445 | + |
| 446 | + // Prints warnings when number of listeners exceeds 15 |
| 447 | + dispatcher.on("foo", fn1); |
| 448 | + expect(console.error).toHaveBeenCalled(); |
| 449 | + |
| 450 | + // ...but still attaches listener anyway |
| 451 | + dispatcher.trigger("foo"); |
| 452 | + expect(fn1).toHaveBeenCalled(); |
| 453 | + }); |
432 | 454 | }); |
433 | 455 | }); |
0 commit comments