index.js
This file
Path
test/index.js
149 lines · 3.5 KiB · JavaScript
Last changed by
refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
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–16why, one step back11describe('mitt#', () => {12 let events, inst;1314 beforeEach( () => {15 inst = mitt();16 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–30why, one step back26 it('should register handler for new type', () => {27 let foo = () => {};28 inst.on('foo', foo);2930 expect(events).to.have.property('foo').that.deep.equals(new Set([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);36refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 37–38why, one step back37 expect(events).to.have.property('constructor').that.deep.equals(new Set([foo]));38 });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);45refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 46–47why, one step back46 expect(events).to.have.property('foo').that.deep.equals(new Set([foo, foo, bar]));47 });48refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 49–53why, one step back49 it('should normalize case', () => {50 let foo = () => {};51 inst.on('FOO', foo);52 inst.on('Bar', foo);53 inst.on('baz:baT!', foo);54refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 55–59why, one step back55 expect(events).to.have.property('foo').that.deep.equals(new Set([foo]));56 expect(events).to.have.property('bar').that.deep.equals(new Set([foo]));57 expect(events).to.have.property('baz:bat!').that.deep.equals(new Set([foo]));58 });59 });60refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 61–65why, one step back61 describe('off()', () => {62 it('should be a function', () => {63 expect(inst)64 .to.have.property('off')65 .that.is.a('function');Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 66–6766 });67refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 68–71why, one step back68 it('should remove handler for type', () => {69 let foo = () => {};70 inst.on('foo', foo);71 inst.off('foo', foo);72refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 73–74why, one step back73 expect(events).to.have.property('foo').that.is.empty;74 });75refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 76–80why, one step back76 it('should normalize case', () => {77 let foo = () => {};78 inst.on('foo', foo);79 inst.on('bar', foo);80 inst.on('baz:bat!', foo);81refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 82–84why, one step back82 inst.off('FOO', foo);83 inst.off('Bar', foo);84 inst.off('baz:baT!', foo);85refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 86–90why, one step back86 expect(events).to.have.property('foo').that.is.empty;87 expect(events).to.have.property('bar').that.is.empty;88 expect(events).to.have.property('baz:bat!').that.is.empty;89 });90 });91refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 92–97why, one step back92 describe('emit()', () => {93 it('should be a function', () => {94 expect(inst)95 .to.have.property('emit')96 .that.is.a('function');97 });98refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 99–100why, one step back99 it('should invoke handler for type', () => {100 let event = { a: 'b' };101refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 102–105why, one step back102 inst.on('foo', (one, two) => {103 expect(one).to.deep.equal(event);104 expect(two).to.be.an('undefined');105 });106refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 107why, one step back107 inst.emit('foo', event);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 108–109108 });109refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 110–117why, one step back110 it('should invoke handler with multiple arguments', () => {111 inst.on('foo', (aaa, bbb, ccc) => {112 expect(aaa).to.be.equal(111);113 expect(bbb).to.be.equal(222);114 expect(ccc).to.be.equal(333);115 });116 inst.emit('foo', 111, 222, 333);117 });118refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 119–122why, one step back119 it('should ignore case', () => {120 let foo = spy(),121 num = 123;122 events.foo = [foo];123refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 124–125why, one step back124 inst.emit('FOO', num);125 inst.emit('Foo', num);126refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 127why, one step back127 let args = foo.args[0];128refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 129–131why, one step back129 expect(foo).to.have.been.calledTwice;130 expect(args).to.be.deep.equal([num, undefined, undefined]);131 });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);140refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 141–142why, one step back141 let args1 = star.args[0],142 args2 = star.args[1];143refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 144–146why, one step back144 expect(star).to.have.been.calledTwice;145 expect(args1).to.deep.equal(['foo', aa, undefined, undefined]);146 expect(args2).to.deep.equal(['bar', aa, undefined, undefined]);Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 147–149147 });148 });149});