index.js
This file
Path
test/index.js
182 lines · 4.4 KiB · JavaScript
Last changed by
Export Mitt types for TS consumers (#101)Jack Franklinbefore adoptioneb2be7c
History of this fileTake it
Export Mitt types for TS consumers (#101)Jack Franklinbefore adoptioneb2be7c
line 1why, one step back1import mitt from '..';2import chai, { expect } from 'chai';3import { spy } from 'sinon';4import sinonChai from 'sinon-chai';5chai.use(sinonChai);6Export Mitt types for TS consumers (#101)Jack Franklinbefore adoptioneb2be7c
lines 7–22why, one step back7describe('mitt', () => {8 it('should default export be a function', () => {9 expect(mitt).to.be.a('function');10 });1112 it('should accept an optional event handler map', () => {13 expect(() => mitt(new Map())).not.to.throw;14 const map = new Map();15 const a = spy();16 const b = spy();17 map.set('foo', [a, b]);18 const events = mitt(map);19 events.emit('foo');20 expect(a).to.have.been.calledOnce;21 expect(b).to.have.been.calledOnce;22 });refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 23why, one step back23});24refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 25–28why, one step back25describe('mitt#', () => {26 let events, inst;2728 beforeEach( () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 29why, one step back29 events = new Map();Merge branch 'agudulin-master' into tunnckoCore-refactorJason Millerbefore adoptione428f3a
line 30why, one step back30 inst = mitt(events);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 31–3231 });32refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 33–38why, one step back33 describe('on()', () => {34 it('should be a function', () => {35 expect(inst)36 .to.have.property('on')37 .that.is.a('function');38 });39refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 40why, one step back40 it('should register handler for new type', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 41why, one step back41 const foo = () => {};refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 42–43why, one step back42 inst.on('foo', foo);43Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 44why, one step back44 expect(events.get('foo')).to.deep.equal([foo]);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 45–4645 });46refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 47why, one step back47 it('should register handlers for any type strings', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 48why, one step back48 const foo = () => {};refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 49why, one step back49 inst.on('constructor', foo);50Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 51why, one step back51 expect(events.get('constructor')).to.deep.equal([foo]);add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
line 52why, one step back52 });53refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 54why, one step back54 it('should append handler for existing type', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 55–56why, one step back55 const foo = () => {};56 const bar = () => {};refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 57–58why, one step back57 inst.on('foo', foo);58 inst.on('foo', bar);59Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 60why, one step back60 expect(events.get('foo')).to.deep.equal([foo, bar]);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 61why, one step back61 });62fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 63why, one step back63 it('should NOT normalize case', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 64why, one step back64 const foo = () => {};refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 65–67why, one step back65 inst.on('FOO', foo);66 inst.on('Bar', foo);67 inst.on('baz:baT!', foo);68Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 69–73why, one step back69 expect(events.get('FOO')).to.deep.equal([foo]);70 expect(events.has('foo')).to.equal(false);71 expect(events.get('Bar')).to.deep.equal([foo]);72 expect(events.has('bar')).to.equal(false);73 expect(events.get('baz:baT!')).to.deep.equal([foo]);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 74why, one step back74 });Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 75–81why, one step back7576 it('can take symbols for event types', () => {77 const foo = () => {};78 const eventType = Symbol('eventType');79 inst.on(eventType, foo);80 expect(events.get(eventType)).to.deep.equal([foo]);81 });Add tests for duplicate listenersJason Millerbefore adoption7313d3a
lines 82–90why, one step back8283 // Adding the same listener multiple times should register it multiple times.84 // See https://nodejs.org/api/events.html#events_emitter_on_eventname_listener85 it('should add duplicate listeners', () => {86 const foo = () => {};87 inst.on('foo', foo);88 inst.on('foo', foo);89 expect(events.get('foo')).to.deep.equal([foo, foo]);90 });refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 91why, one step back91 });92refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 93–97why, one step back93 describe('off()', () => {94 it('should be a function', () => {95 expect(inst)96 .to.have.property('off')97 .that.is.a('function');Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 98–9998 });99refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 100why, one step back100 it('should remove handler for type', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 101why, one step back101 const foo = () => {};refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 102–103why, one step back102 inst.on('foo', foo);103 inst.off('foo', foo);104Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 105why, one step back105 expect(events.get('foo')).to.be.empty;refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 106why, one step back106 });107fix failing test from before removal of case normalizationJason Millerbefore adoption9953570
line 108why, one step back108 it('should NOT normalize case', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 109why, one step back109 const foo = () => {};fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
lines 110–111why, one step back110 inst.on('FOO', foo);111 inst.on('Bar', foo);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 112why, one step back112 inst.on('baz:bat!', foo);113refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 114–116why, one step back114 inst.off('FOO', foo);115 inst.off('Bar', foo);116 inst.off('baz:baT!', foo);117Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 118–122why, one step back118 expect(events.get('FOO')).to.be.empty;119 expect(events.has('foo')).to.equal(false);120 expect(events.get('Bar')).to.be.empty;121 expect(events.has('bar')).to.equal(false);122 expect(events.get('baz:bat!')).to.have.lengthOf(1);Add tests for duplicate listenersJason Millerbefore adoption7313d3a
lines 123–132why, one step back123 });124125 it('should remove only the first matching listener', () => {126 const foo = () => {};127 inst.on('foo', foo);128 inst.on('foo', foo);129 inst.off('foo', foo);130 expect(events.get('foo')).to.deep.equal([foo]);131 inst.off('foo', foo);132 expect(events.get('foo')).to.deep.equal([]);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 133–134why, one step back133 });134 });135refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 136–141why, one step back136 describe('emit()', () => {137 it('should be a function', () => {138 expect(inst)139 .to.have.property('emit')140 .that.is.a('function');141 });142refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 143why, one step back143 it('should invoke handler for type', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 144why, one step back144 const event = { a: 'b' };145refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 146why, one step back146 inst.on('foo', (one, two) => {add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
lines 147–149why, one step back147 expect(one).to.deep.equal(event);148 expect(two).to.be.an('undefined');149 });150refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 151why, one step back151 inst.emit('foo', event);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 152–153152 });153fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 154why, one step back154 it('should NOT ignore case', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 155why, one step back155 const onFoo = spy(),Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
line 156why, one step back156 onFOO = spy();Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 157–158why, one step back157 events.set('Foo', [onFoo]);158 events.set('FOO', [onFOO]);159Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 160–161why, one step back160 inst.emit('Foo', 'Foo arg');161 inst.emit('FOO', 'FOO arg');162Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 163–164why, one step back163 expect(onFoo).to.have.been.calledOnce.and.calledWith('Foo arg');164 expect(onFOO).to.have.been.calledOnce.and.calledWith('FOO arg');refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 165why, one step back165 });166refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 167why, one step back167 it('should invoke * handlers', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 168why, one step back168 const star = spy(),Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 169–171why, one step back169 ea = { a: 'a' },170 eb = { b: 'b' };171Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 172why, one step back172 events.set('*', [star]);173Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 174–175why, one step back174 inst.emit('foo', ea);175 expect(star).to.have.been.calledOnce.and.calledWith('foo', ea);Update all dependenciesJason Millerbefore adoptiondd64eea
line 176why, one step back176 star.resetHistory();177Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 178–179why, one step back178 inst.emit('bar', eb);179 expect(star).to.have.been.calledOnce.and.calledWith('bar', eb);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 180–182180 });181 });182});