Skip to content
Myr

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 file

Take it

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 1–6
1import mitt from '../src';
2import chai, { expect } from 'chai';3import { spy } from 'sinon';4import sinonChai from 'sinon-chai';5chai.use(sinonChai);6

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 7–9why, one step back
7it('should default export be a function', () => {
8 expect(mitt).to.be.a('function');9});

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 10
10

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 11–14why, one step back
11describe('mitt#', () => {
12 let events, inst;1314 beforeEach( () => {

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 15why, one step back
15 events = new Map();

Merge branch 'agudulin-master' into tunnckoCore-refactorJason Millerbefore adoptione428f3a

line 16why, one step back
16 inst = mitt(events);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 17–18
17 });
18

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 19–24why, one step back
19 describe('on()', () => {
20 it('should be a function', () => {21 expect(inst)22 .to.have.property('on')23 .that.is.a('function');24 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 25
25

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 26why, one step back
26 it('should register handler for new type', () => {

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 27why, one step back
27 const foo = () => {};

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 28–29why, one step back
28 inst.on('foo', foo);
29

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 30why, one step back
30 expect(events.get('foo')).to.deep.equal([foo]);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 31–32
31 });
32

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 33why, one step back
33 it('should register handlers for any type strings', () => {

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 34why, one step back
34 const foo = () => {};

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 35why, one step back
35 inst.on('constructor', foo);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 36
36

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 37why, one step back
37 expect(events.get('constructor')).to.deep.equal([foo]);

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

line 38why, one step back
38 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 39
39

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 40why, one step back
40 it('should append handler for existing type', () => {

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

lines 41–42why, one step back
41 const foo = () => {};
42 const bar = () => {};

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 43–44why, one step back
43 inst.on('foo', foo);
44 inst.on('foo', bar);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 45
45

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 46why, one step back
46 expect(events.get('foo')).to.deep.equal([foo, bar]);

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 47why, one step back
47 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 48
48

fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b

line 49why, one step back
49 it('should NOT normalize case', () => {

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 50why, one step back
50 const foo = () => {};

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 51–53why, one step back
51 inst.on('FOO', foo);
52 inst.on('Bar', foo);53 inst.on('baz:baT!', foo);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 54
54

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

lines 55–59why, one step back
55 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 back
60 });

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

lines 61–67why, one step back
61
62 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 back
68 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 69
69

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 70–74why, one step back
70 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–76
75 });
76

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 77why, one step back
77 it('should remove handler for type', () => {

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 78why, one step back
78 const foo = () => {};

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 79–80why, one step back
79 inst.on('foo', foo);
80 inst.off('foo', foo);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 81
81

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 82why, one step back
82 expect(events.get('foo')).to.be.empty;

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 83why, one step back
83 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 84
84

fix failing test from before removal of case normalizationJason Millerbefore adoption9953570

line 85why, one step back
85 it('should NOT normalize case', () => {

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 86why, one step back
86 const foo = () => {};

fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b

lines 87–88why, one step back
87 inst.on('FOO', foo);
88 inst.on('Bar', foo);

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 89why, one step back
89 inst.on('baz:bat!', foo);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 90
90

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 91–93why, one step back
91 inst.off('FOO', foo);
92 inst.off('Bar', foo);93 inst.off('baz:baT!', foo);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 94
94

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

lines 95–99why, one step back
95 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 back
100 });
101 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 102
102

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 103–108why, one step back
103 describe('emit()', () => {
104 it('should be a function', () => {105 expect(inst)106 .to.have.property('emit')107 .that.is.a('function');108 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 109
109

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 110why, one step back
110 it('should invoke handler for type', () => {

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 111why, one step back
111 const event = { a: 'b' };

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 112
112

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 113why, one step back
113 inst.on('foo', (one, two) => {

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 114–116why, one step back
114 expect(one).to.deep.equal(event);
115 expect(two).to.be.an('undefined');116 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 117
117

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 118why, one step back
118 inst.emit('foo', event);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 119–120
119 });
120

fix: switch Set with array; update tests; drop toLowerCase()tunnckoCorebefore adoption0c8202b

line 121why, one step back
121 it('should NOT ignore case', () => {

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 122why, one step back
122 const onFoo = spy(),

Use sinon-chai methods for assertionsJason Millerbefore adoption4540116

line 123why, one step back
123 onFOO = spy();

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

lines 124–125why, one step back
124 events.set('Foo', [onFoo]);
125 events.set('FOO', [onFOO]);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 126
126

Use sinon-chai methods for assertionsJason Millerbefore adoption4540116

lines 127–128why, one step back
127 inst.emit('Foo', 'Foo arg');
128 inst.emit('FOO', 'FOO arg');

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 129
129

Use sinon-chai methods for assertionsJason Millerbefore adoption4540116

lines 130–131why, one step back
130 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 back
132 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 133
133

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 134why, one step back
134 it('should invoke * handlers', () => {

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 135why, one step back
135 const star = spy(),

Use sinon-chai methods for assertionsJason Millerbefore adoption4540116

lines 136–138why, one step back
136 ea = { a: 'a' },
137 eb = { b: 'b' };138

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 139why, one step back
139 events.set('*', [star]);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 140
140

Use sinon-chai methods for assertionsJason Millerbefore adoption4540116

lines 141–143why, one step back
141 inst.emit('foo', ea);
142 expect(star).to.have.been.calledOnce.and.calledWith('foo', ea);143 star.reset();

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 144
144

Use sinon-chai methods for assertionsJason Millerbefore adoption4540116

lines 145–146why, one step back
145 inst.emit('bar', eb);
146 expect(star).to.have.been.calledOnce.and.calledWith('bar', eb);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 147–149
147 });
148 });149});