index.js
This file
Path
test/index.js
168 lines · 4.1 KiB · JavaScript
Last changed by
Update all dependenciesJason Millerbefore adoptiondd64eea
History of this fileTake it
1import mitt from '../src';2import chai, { expect } from 'chai';3import { spy } from 'sinon';4import sinonChai from 'sinon-chai';5chai.use(sinonChai);6refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 7–9why, one step back7it('should default export be a function', () => {8 expect(mitt).to.be.a('function');9});10refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 11–14why, one step back11describe('mitt#', () => {12 let events, inst;1314 beforeEach( () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 15why, one step back15 events = new Map();Merge branch 'agudulin-master' into tunnckoCore-refactorJason Millerbefore adoptione428f3a
line 16why, one step back16 inst = mitt(events);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 17–1817 });18refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 19–24why, one step back19 describe('on()', () => {20 it('should be a function', () => {21 expect(inst)22 .to.have.property('on')23 .that.is.a('function');24 });25refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 26why, one step back26 it('should register handler for new type', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 27why, one step back27 const foo = () => {};refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 28–29why, one step back28 inst.on('foo', foo);29Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 30why, one step back30 expect(events.get('foo')).to.deep.equal([foo]);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 31–3231 });32refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 33why, one step back33 it('should register handlers for any type strings', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 34why, one step back34 const foo = () => {};refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 35why, one step back35 inst.on('constructor', foo);36Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 37why, one step back37 expect(events.get('constructor')).to.deep.equal([foo]);add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
line 38why, one step back38 });39refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 40why, one step back40 it('should append handler for existing type', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 41–42why, one step back41 const foo = () => {};42 const bar = () => {};refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 43–44why, one step back43 inst.on('foo', foo);44 inst.on('foo', bar);45Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 46why, one step back46 expect(events.get('foo')).to.deep.equal([foo, bar]);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 47why, one step back47 });48fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 49why, one step back49 it('should NOT normalize case', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 50why, one step back50 const foo = () => {};refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 51–53why, one step back51 inst.on('FOO', foo);52 inst.on('Bar', foo);53 inst.on('baz:baT!', foo);54Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 55–59why, one step back55 expect(events.get('FOO')).to.deep.equal([foo]);56 expect(events.has('foo')).to.equal(false);57 expect(events.get('Bar')).to.deep.equal([foo]);58 expect(events.has('bar')).to.equal(false);59 expect(events.get('baz:baT!')).to.deep.equal([foo]);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 60why, one step back60 });Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 61–67why, one step back6162 it('can take symbols for event types', () => {63 const foo = () => {};64 const eventType = Symbol('eventType');65 inst.on(eventType, foo);66 expect(events.get(eventType)).to.deep.equal([foo]);67 });Add tests for duplicate listenersJason Millerbefore adoption7313d3a
lines 68–76why, one step back6869 // Adding the same listener multiple times should register it multiple times.70 // See https://nodejs.org/api/events.html#events_emitter_on_eventname_listener71 it('should add duplicate listeners', () => {72 const foo = () => {};73 inst.on('foo', foo);74 inst.on('foo', foo);75 expect(events.get('foo')).to.deep.equal([foo, foo]);76 });refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 77why, one step back77 });78refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 79–83why, one step back79 describe('off()', () => {80 it('should be a function', () => {81 expect(inst)82 .to.have.property('off')83 .that.is.a('function');Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 84–8584 });85refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 86why, one step back86 it('should remove handler for type', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 87why, one step back87 const foo = () => {};refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 88–89why, one step back88 inst.on('foo', foo);89 inst.off('foo', foo);90Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 91why, one step back91 expect(events.get('foo')).to.be.empty;refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 92why, one step back92 });93fix failing test from before removal of case normalizationJason Millerbefore adoption9953570
line 94why, one step back94 it('should NOT normalize case', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 95why, one step back95 const foo = () => {};fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
lines 96–97why, one step back96 inst.on('FOO', foo);97 inst.on('Bar', foo);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 98why, one step back98 inst.on('baz:bat!', foo);99refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 100–102why, one step back100 inst.off('FOO', foo);101 inst.off('Bar', foo);102 inst.off('baz:baT!', foo);103Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 104–108why, one step back104 expect(events.get('FOO')).to.be.empty;105 expect(events.has('foo')).to.equal(false);106 expect(events.get('Bar')).to.be.empty;107 expect(events.has('bar')).to.equal(false);108 expect(events.get('baz:bat!')).to.have.lengthOf(1);Add tests for duplicate listenersJason Millerbefore adoption7313d3a
lines 109–118why, one step back109 });110111 it('should remove only the first matching listener', () => {112 const foo = () => {};113 inst.on('foo', foo);114 inst.on('foo', foo);115 inst.off('foo', foo);116 expect(events.get('foo')).to.deep.equal([foo]);117 inst.off('foo', foo);118 expect(events.get('foo')).to.deep.equal([]);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 119–120why, one step back119 });120 });121refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 122–127why, one step back122 describe('emit()', () => {123 it('should be a function', () => {124 expect(inst)125 .to.have.property('emit')126 .that.is.a('function');127 });128refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 129why, one step back129 it('should invoke handler for type', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 130why, one step back130 const event = { a: 'b' };131refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 132why, one step back132 inst.on('foo', (one, two) => {add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
lines 133–135why, one step back133 expect(one).to.deep.equal(event);134 expect(two).to.be.an('undefined');135 });136refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 137why, one step back137 inst.emit('foo', event);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 138–139138 });139fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 140why, one step back140 it('should NOT ignore case', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 141why, one step back141 const onFoo = spy(),Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
line 142why, one step back142 onFOO = spy();Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 143–144why, one step back143 events.set('Foo', [onFoo]);144 events.set('FOO', [onFOO]);145Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 146–147why, one step back146 inst.emit('Foo', 'Foo arg');147 inst.emit('FOO', 'FOO arg');148Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 149–150why, one step back149 expect(onFoo).to.have.been.calledOnce.and.calledWith('Foo arg');150 expect(onFOO).to.have.been.calledOnce.and.calledWith('FOO arg');refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 151why, one step back151 });152refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 153why, one step back153 it('should invoke * handlers', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 154why, one step back154 const star = spy(),Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 155–157why, one step back155 ea = { a: 'a' },156 eb = { b: 'b' };157Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 158why, one step back158 events.set('*', [star]);159Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 160–161why, one step back160 inst.emit('foo', ea);161 expect(star).to.have.been.calledOnce.and.calledWith('foo', ea);Update all dependenciesJason Millerbefore adoptiondd64eea
line 162why, one step back162 star.resetHistory();163Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 164–165why, one step back164 inst.emit('bar', eb);165 expect(star).to.have.been.calledOnce.and.calledWith('bar', eb);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 166–168166 });167 });168});