Skip to content

Commit

Permalink
[test] Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Mar 21, 2016
1 parent ee09a9b commit 4e1a4cb
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ describe('Ultron', function () {
assume('__ultron' in once).is.false();
assume('__ultron' in on).is.false();

ee.removeAllListeners();
ultron.destroy();

ee = new EE();
Expand Down Expand Up @@ -215,14 +216,12 @@ describe('Ultron', function () {
ultron.remove('foo');
assume(ee.listeners('foo').length).equals(1);
assume(ee.listeners('foo')[0]).equals(foo);
});

it('removes only our assigned `once` listeners from regular EE', function () {
var ee = new EE()
, ultron = new Ultron(ee);
ee.removeAllListeners();
ultron.destroy();

function foo() {}
function bar() {}
ee = new EE();
ultron = new Ultron(ee);

ee.once('foo', foo);
ultron.once('foo', bar);
Expand All @@ -247,6 +246,23 @@ describe('Ultron', function () {

assume(ee.listeners('foo').length).equals(0);
assume(ee.listeners('bar').length).equals(0);

ee.removeAllListeners();
ultron.destroy();

ee = new EE();
ultron = new Ultron(ee);

ultron.on('foo', foo);
ultron.on('bar', bar);

assume(ee.listeners('foo').length).equals(1);
assume(ee.listeners('bar').length).equals(1);

ultron.remove();

assume(ee.listeners('foo').length).equals(0);
assume(ee.listeners('bar').length).equals(0);
});

it('removes multiple listeners based on args', function () {
Expand Down Expand Up @@ -318,6 +334,35 @@ describe('Ultron', function () {
ultron.remove();
assume(ee.listeners(s).length).equals(1);
assume(ee.listeners(s)[0]).equals(foo);

ee.removeAllListeners();
ultron.destroy();

ee = new EE();
ultron = new Ultron(ee);

ee.on(s, foo);
ultron.on(s, bar);
assume(ee.listeners(s).length).equals(2);

ultron.remove(s);
assume(ee.listeners(s).length).equals(1);
assume(ee.listeners(s)[0]).equals(foo);

ultron.once(s, bar);
assume(ee.listeners(s).length).equals(2);

ultron.remove(s);
assume(ee.listeners(s).length).equals(1);
assume(ee.listeners(s)[0]).equals(foo);

ultron.on(s, bar);
ultron.on(s, baz);
assume(ee.listeners(s).length).equals(3);

ultron.remove();
assume(ee.listeners(s).length).equals(1);
assume(ee.listeners(s)[0]).equals(foo);
});
});

Expand Down

0 comments on commit 4e1a4cb

Please sign in to comment.