index.js
This file
Path
test/index.js
149 lines · 3.5 KiB · JavaScript
Last changed by
remove "drop support for emitting multiple args" thing as per https://github.com/developit/mitt/pull/19#issuecomment-273344689tunnckoCorebefore adoptionf4c60f4
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–15why, one step back11describe('mitt#', () => {12 let events, inst;1314 beforeEach( () => {15 inst = mitt();add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
line 16why, one step back16 events = inst.all;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
lines 26–29why, one step back26 it('should register handler for new type', () => {27 let foo = () => {};28 inst.on('foo', foo);29fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 30why, one step back30 expect(events).to.have.property('foo').that.deep.equals([foo]);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 31–3231 });32refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 33–35why, one step back33 it('should register handlers for any type strings', () => {34 let foo = () => {};35 inst.on('constructor', foo);36fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 37why, one step back37 expect(events).to.have.property('constructor').that.deep.equals([foo]);add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
line 38why, one step back38 });39refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 40–44why, one step back40 it('should append handler for existing type', () => {41 let foo = () => {};42 let bar = () => {};43 inst.on('foo', foo);44 inst.on('foo', bar);45fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 46why, one step back46 expect(events).to.have.property('foo').that.deep.equals([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', () => {refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 50–53why, one step back50 let foo = () => {};51 inst.on('FOO', foo);52 inst.on('Bar', foo);53 inst.on('baz:baT!', foo);54fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
lines 55–59why, one step back55 expect(events).to.have.property('FOO').that.deep.equals([foo]);56 expect(events).to.not.have.property('foo');57 expect(events).to.have.property('Bar').that.deep.equals([foo]);58 expect(events).to.not.have.property('bar');59 expect(events).to.have.property('baz:baT!').that.deep.equals([foo]);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 60–61why, one step back60 });61 });62refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 63–67why, one step back63 describe('off()', () => {64 it('should be a function', () => {65 expect(inst)66 .to.have.property('off')67 .that.is.a('function');Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 68–6968 });69refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 70–73why, one step back70 it('should remove handler for type', () => {71 let foo = () => {};72 inst.on('foo', foo);73 inst.off('foo', foo);74refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 75–76why, one step back75 expect(events).to.have.property('foo').that.is.empty;76 });77refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 78–79why, one step back78 it('should normalize case', () => {79 let foo = () => {};fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
lines 80–81why, one step back80 inst.on('FOO', foo);81 inst.on('Bar', foo);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 82why, one step back82 inst.on('baz:bat!', foo);83refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 84–86why, one step back84 inst.off('FOO', foo);85 inst.off('Bar', foo);86 inst.off('baz:baT!', foo);87fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
lines 88–92why, one step back88 expect(events).to.have.property('FOO').that.is.empty;89 expect(events).to.not.have.property('foo');90 expect(events).to.have.property('Bar').that.is.empty;91 expect(events).to.not.have.property('bar');92 expect(events).to.have.property('baz:baT!').that.is.empty;refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 93–94why, one step back93 });94 });95refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 96–101why, one step back96 describe('emit()', () => {97 it('should be a function', () => {98 expect(inst)99 .to.have.property('emit')100 .that.is.a('function');101 });102refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 103why, one step back103 it('should invoke handler for type', () => {add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
line 104why, one step back104 let event = { a: 'b' };105refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 106why, one step back106 inst.on('foo', (one, two) => {add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
lines 107–109why, one step back107 expect(one).to.deep.equal(event);108 expect(two).to.be.an('undefined');109 });110refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 111why, one step back111 inst.emit('foo', event);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 112–113112 });113fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 114why, one step back114 it('should NOT ignore case', () => {refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 115why, one step back115 let foo = spy(),fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
line 116why, one step back116 bar = spy(),refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 117why, one step back117 num = 123;fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
lines 118–119why, one step back118 events.Foo = [foo];119 events.FOO = [bar];120refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 121–122why, one step back121 inst.emit('FOO', num);122 inst.emit('Foo', num);123fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
lines 124–125why, one step back124 let args1 = foo.args[0];125 let args2 = bar.args[0];126fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b
lines 127–128why, one step back127 expect(foo).to.have.been.calledOnce;128 expect(bar).to.have.been.calledOnce;remove "drop support for emitting multiple args" thing as per https://github.com/developit/mitt/pull/19#issuecomment-273344689tunnckoCorebefore adoptionf4c60f4
lines 129–130why, one step back129 expect(args1).to.be.deep.equal([num]);130 expect(args2).to.be.deep.equal([num]);refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 131why, one step back131 });132refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 133–136why, one step back133 it('should invoke * handlers', () => {134 let star = spy(),135 aa = 'bb';136 events['*'] = [star];137refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 138–139why, one step back138 inst.emit('foo', aa);139 inst.emit('bar', aa);140add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c
line 141why, one step back141 let args1 = star.args[0],refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 142why, one step back142 args2 = star.args[1];143refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 144why, one step back144 expect(star).to.have.been.calledTwice;remove "drop support for emitting multiple args" thing as per https://github.com/developit/mitt/pull/19#issuecomment-273344689tunnckoCorebefore adoptionf4c60f4
lines 145–146why, one step back145 expect(args1).to.deep.equal(['foo', aa]);146 expect(args2).to.deep.equal(['bar', aa]);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 147–149147 });148 });149});