diff options
Diffstat (limited to 'test/index.js')
| -rw-r--r-- | test/index.js | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/test/index.js b/test/index.js index 3e0ef78..554f1f1 100644 --- a/test/index.js +++ b/test/index.js @@ -12,7 +12,7 @@ describe('mitt#', () => { let events, inst; beforeEach( () => { - events = Object.create(null); + events = new Map(); inst = mitt(events); }); @@ -24,39 +24,46 @@ describe('mitt#', () => { }); it('should register handler for new type', () => { - let foo = () => {}; + const foo = () => {}; inst.on('foo', foo); - expect(events).to.have.property('foo').that.deep.equals([foo]); + expect(events.get('foo')).to.deep.equal([foo]); }); it('should register handlers for any type strings', () => { - let foo = () => {}; + const foo = () => {}; inst.on('constructor', foo); - expect(events).to.have.property('constructor').that.deep.equals([foo]); + expect(events.get('constructor')).to.deep.equal([foo]); }); it('should append handler for existing type', () => { - let foo = () => {}; - let bar = () => {}; + const foo = () => {}; + const bar = () => {}; inst.on('foo', foo); inst.on('foo', bar); - expect(events).to.have.property('foo').that.deep.equals([foo, bar]); + expect(events.get('foo')).to.deep.equal([foo, bar]); }); it('should NOT normalize case', () => { - let foo = () => {}; + const foo = () => {}; inst.on('FOO', foo); inst.on('Bar', foo); inst.on('baz:baT!', foo); - expect(events).to.have.property('FOO').that.deep.equals([foo]); - expect(events).to.not.have.property('foo'); - expect(events).to.have.property('Bar').that.deep.equals([foo]); - expect(events).to.not.have.property('bar'); - expect(events).to.have.property('baz:baT!').that.deep.equals([foo]); + expect(events.get('FOO')).to.deep.equal([foo]); + expect(events.has('foo')).to.equal(false); + expect(events.get('Bar')).to.deep.equal([foo]); + expect(events.has('bar')).to.equal(false); + expect(events.get('baz:baT!')).to.deep.equal([foo]); + }); + + it('can take symbols for event types', () => { + const foo = () => {}; + const eventType = Symbol('eventType'); + inst.on(eventType, foo); + expect(events.get(eventType)).to.deep.equal([foo]); }); }); @@ -68,15 +75,15 @@ describe('mitt#', () => { }); it('should remove handler for type', () => { - let foo = () => {}; + const foo = () => {}; inst.on('foo', foo); inst.off('foo', foo); - expect(events).to.have.property('foo').that.is.empty; + expect(events.get('foo')).to.be.empty; }); it('should NOT normalize case', () => { - let foo = () => {}; + const foo = () => {}; inst.on('FOO', foo); inst.on('Bar', foo); inst.on('baz:bat!', foo); @@ -85,11 +92,11 @@ describe('mitt#', () => { inst.off('Bar', foo); inst.off('baz:baT!', foo); - expect(events).to.have.property('FOO').that.is.empty; - expect(events).to.not.have.property('foo'); - expect(events).to.have.property('Bar').that.is.empty; - expect(events).to.not.have.property('bar'); - expect(events).to.have.property('baz:bat!').with.length(1); + expect(events.get('FOO')).to.be.empty; + expect(events.has('foo')).to.equal(false); + expect(events.get('Bar')).to.be.empty; + expect(events.has('bar')).to.equal(false); + expect(events.get('baz:bat!')).to.have.lengthOf(1); }); }); @@ -101,7 +108,7 @@ describe('mitt#', () => { }); it('should invoke handler for type', () => { - let event = { a: 'b' }; + const event = { a: 'b' }; inst.on('foo', (one, two) => { expect(one).to.deep.equal(event); @@ -112,10 +119,10 @@ describe('mitt#', () => { }); it('should NOT ignore case', () => { - let onFoo = spy(), + const onFoo = spy(), onFOO = spy(); - events.Foo = [onFoo]; - events.FOO = [onFOO]; + events.set('Foo', [onFoo]); + events.set('FOO', [onFOO]); inst.emit('Foo', 'Foo arg'); inst.emit('FOO', 'FOO arg'); @@ -125,11 +132,11 @@ describe('mitt#', () => { }); it('should invoke * handlers', () => { - let star = spy(), + const star = spy(), ea = { a: 'a' }, eb = { b: 'b' }; - events['*'] = [star]; + events.set('*', [star]); inst.emit('foo', ea); expect(star).to.have.been.calledOnce.and.calledWith('foo', ea); |
