Skip to content
Myr

index.js

This file

Path

test/index.js

157 lines · 3.7 KiB · JavaScript

Last changed by

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

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–15why, one step back
11describe('mitt#', () => {
12 let events, inst;1314 beforeEach( () => {15 inst = mitt();

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

line 16why, one step back
16 events = inst.all;

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

lines 26–29why, one step back
26 it('should register handler for new type', () => {
27 let foo = () => {};28 inst.on('foo', foo);29

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

line 30why, one step back
30 expect(events).to.have.property('foo').that.deep.equals([foo]);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 31–32
31 });
32

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

lines 33–35why, one step back
33 it('should register handlers for any type strings', () => {
34 let foo = () => {};35 inst.on('constructor', foo);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 36
36

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

line 37why, one step back
37 expect(events).to.have.property('constructor').that.deep.equals([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

lines 40–44why, one step back
40 it('should append handler for existing type', () => {
41 let foo = () => {};42 let bar = () => {};43 inst.on('foo', foo);44 inst.on('foo', bar);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 45
45

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

line 46why, one step back
46 expect(events).to.have.property('foo').that.deep.equals([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', () => {

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

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 54
54

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

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 62
62

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

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

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

lines 70–73why, one step back
70 it('should remove handler for type', () => {
71 let foo = () => {};72 inst.on('foo', foo);73 inst.off('foo', foo);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 74
74

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

lines 75–76why, one step back
75 expect(events).to.have.property('foo').that.is.empty;
76 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 77
77

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

lines 78–79why, one step back
78 it('should normalize case', () => {
79 let foo = () => {};

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

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

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

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 83
83

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

lines 84–86why, one step back
84 inst.off('FOO', foo);
85 inst.off('Bar', foo);86 inst.off('baz:baT!', foo);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 87
87

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

lines 88–92why, one step back
88 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 back
93 });
94 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 95
95

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

lines 96–101why, one step back
96 describe('emit()', () => {
97 it('should be a function', () => {98 expect(inst)99 .to.have.property('emit')100 .that.is.a('function');101 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 102
102

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

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

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

line 104why, one step back
104 let event = { a: 'b' };

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 105
105

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

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

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 107–109why, one step back
107 expect(one).to.deep.equal(event);
108 expect(two).to.be.an('undefined');109 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 110
110

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

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 112–113
112 });
113

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

lines 114–115why, one step back
114 it('should invoke handler with multiple (max 2) arguments', () => {
115 inst.on('foo', (aaa, bbb) => {

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

lines 116–118why, one step back
116 expect(aaa).to.be.equal(111);
117 expect(bbb).to.be.equal(222);118 });

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

line 119why, one step back
119 inst.emit('foo', 111, 222);

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

line 120why, one step back
120 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 121
121

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

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

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

line 123why, one step back
123 let foo = spy(),

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

line 124why, one step back
124 bar = spy(),

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

line 125why, one step back
125 num = 123;

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

lines 126–127why, one step back
126 events.Foo = [foo];
127 events.FOO = [bar];

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 128
128

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

lines 129–130why, one step back
129 inst.emit('FOO', num);
130 inst.emit('Foo', num);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 131
131

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

lines 132–133why, one step back
132 let args1 = foo.args[0];
133 let args2 = bar.args[0];

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 134
134

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

lines 135–138why, one step back
135 expect(foo).to.have.been.calledOnce;
136 expect(bar).to.have.been.calledOnce;137 expect(args1).to.be.deep.equal([num, undefined]);138 expect(args2).to.be.deep.equal([num, undefined]);

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

line 139why, one step back
139 });

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 140
140

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

lines 141–144why, one step back
141 it('should invoke * handlers', () => {
142 let star = spy(),143 aa = 'bb';144 events['*'] = [star];

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 145
145

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

lines 146–147why, one step back
146 inst.emit('foo', aa);
147 inst.emit('bar', aa);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 148
148

add editorconfig, fix original identationtunnckoCorebefore adoptione7c222c

line 149why, one step back
149 let args1 = star.args[0],

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

line 150why, one step back
150 args2 = star.args[1];

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 151
151

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

line 152why, one step back
152 expect(star).to.have.been.calledTwice;

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

lines 153–154why, one step back
153 expect(args1).to.deep.equal(['foo', aa, undefined]);
154 expect(args2).to.deep.equal(['bar', aa, undefined]);

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 155–157
155 });
156 });157});