index.js
This file
Path
test/index.js
149 lines · 3.5 KiB · JavaScript
Last changed by
Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
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 });refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 68why, one step back68 });69refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 70–74why, one step back70 describe('off()', () => {71 it('should be a function', () => {72 expect(inst)73 .to.have.property('off')74 .that.is.a('function');Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 75–7675 });76refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 77why, one step back77 it('should remove handler for type', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 78why, one step back78 const foo = () => {};refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 79–80why, one step back79 inst.on('foo', foo);80 inst.off('foo', foo);81Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 82why, one step back82 expect(events.get('foo')).to.be.empty;refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 83why, one step back83 });84fix failing test from before removal of case normalizationJason Millerbefore adoption9953570
line 85why, one step back85 it('should NOT normalize case', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 86why, one step back86 const foo = () => {};fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
lines 87–88why, one step back87 inst.on('FOO', foo);88 inst.on('Bar', foo);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 89why, one step back89 inst.on('baz:bat!', foo);90refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 91–93why, one step back91 inst.off('FOO', foo);92 inst.off('Bar', foo);93 inst.off('baz:baT!', foo);94Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 95–99why, one step back95 expect(events.get('FOO')).to.be.empty;96 expect(events.has('foo')).to.equal(false);97 expect(events.get('Bar')).to.be.empty;98 expect(events.has('bar')).to.equal(false);99 expect(events.get('baz:bat!')).to.have.lengthOf(1);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 100–101why, one step back100 });101 });102refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 103–108why, one step back103 describe('emit()', () => {104 it('should be a function', () => {105 expect(inst)106 .to.have.property('emit')107 .that.is.a('function');108 });109refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 110why, one step back110 it('should invoke handler for type', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 111why, one step back111 const event = { a: 'b' };112refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 113why, one step back113 inst.on('foo', (one, two) => {add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
lines 114–116why, one step back114 expect(one).to.deep.equal(event);115 expect(two).to.be.an('undefined');116 });117refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 118why, one step back118 inst.emit('foo', event);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 119–120119 });120fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 121why, one step back121 it('should NOT ignore case', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 122why, one step back122 const onFoo = spy(),Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
line 123why, one step back123 onFOO = spy();Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 124–125why, one step back124 events.set('Foo', [onFoo]);125 events.set('FOO', [onFOO]);126Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 127–128why, one step back127 inst.emit('Foo', 'Foo arg');128 inst.emit('FOO', 'FOO arg');129Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 130–131why, one step back130 expect(onFoo).to.have.been.calledOnce.and.calledWith('Foo arg');131 expect(onFOO).to.have.been.calledOnce.and.calledWith('FOO arg');refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 132why, one step back132 });133refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 134why, one step back134 it('should invoke * handlers', () => {Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 135why, one step back135 const star = spy(),Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 136–138why, one step back136 ea = { a: 'a' },137 eb = { b: 'b' };138Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 139why, one step back139 events.set('*', [star]);140Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 141–143why, one step back141 inst.emit('foo', ea);142 expect(star).to.have.been.calledOnce.and.calledWith('foo', ea);143 star.reset();144Use sinon-chai methods for assertionsJason Millerbefore adoption4540116
lines 145–146why, one step back145 inst.emit('bar', eb);146 expect(star).to.have.been.calledOnce.and.calledWith('bar', eb);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 147–149147 });148 });149});