Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/filterNotifier.js

Issue 29977555: Issue 7202 - Add hasListeners method to EventEmitter (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add tests Created Jan. 9, 2019, 5 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/events.js ('K') | « lib/events.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 filterNotifier.on("foo", listener); 43 filterNotifier.on("foo", listener);
44 } 44 }
45 45
46 function removeListener(listener) 46 function removeListener(listener)
47 { 47 {
48 filterNotifier.off("foo", listener); 48 filterNotifier.off("foo", listener);
49 } 49 }
50 50
51 function compareListeners(test, testDescription, list) 51 function compareListeners(test, testDescription, list)
52 { 52 {
53 test.equal(filterNotifier.hasListeners(), list.length > 0, testDescription);
54 test.equal(filterNotifier.hasListeners("foo"), list.length > 0,
55 testDescription);
56
57 test.equal(filterNotifier.hasListeners("bar"), false, testDescription);
58
53 let result1 = triggeredListeners = []; 59 let result1 = triggeredListeners = [];
54 filterNotifier.emit("foo", {bar: true}); 60 filterNotifier.emit("foo", {bar: true});
55 61
56 let result2 = triggeredListeners = []; 62 let result2 = triggeredListeners = [];
57 for (let observer of list) 63 for (let observer of list)
58 observer({bar: true}); 64 observer({bar: true});
59 65
60 test.deepEqual(result1, result2, testDescription); 66 test.deepEqual(result1, result2, testDescription);
61 } 67 }
62 68
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 }; 114 };
109 let listener2 = listeners[1]; 115 let listener2 = listeners[1];
110 addListener(listener1); 116 addListener(listener1);
111 addListener(listener2); 117 addListener(listener2);
112 118
113 compareListeners(test, "Initial call", [listener1, listener2]); 119 compareListeners(test, "Initial call", [listener1, listener2]);
114 compareListeners(test, "Subsequent calls", [listener2]); 120 compareListeners(test, "Subsequent calls", [listener2]);
115 121
116 test.done(); 122 test.done();
117 }; 123 };
OLDNEW
« lib/events.js ('K') | « lib/events.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld