diff options
| author | tunnckoCore <[email protected]> | 2017-01-17 20:26:33 +0200 |
|---|---|---|
| committer | tunnckoCore <[email protected]> | 2017-01-17 20:26:33 +0200 |
| commit | 0c8202b740545268b3ab1e23dbaf0992490824e1 (patch) | |
| tree | 921df0a88edc015cedc352471afa676ba530307a /test | |
| parent | e7c222c0e840b34eb56566da453d7a12a257c61f (diff) | |
fix: switch Set with array; update tests; drop toLowerCase()
Diffstat (limited to 'test')
| -rw-r--r-- | test/index.js | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/test/index.js b/test/index.js index d0bcefd..f552392 100644 --- a/test/index.js +++ b/test/index.js @@ -27,14 +27,14 @@ describe('mitt#', () => { let foo = () => {}; inst.on('foo', foo); - expect(events).to.have.property('foo').that.deep.equals(new Set([foo])); + expect(events).to.have.property('foo').that.deep.equals([foo]); }); it('should register handlers for any type strings', () => { let foo = () => {}; inst.on('constructor', foo); - expect(events).to.have.property('constructor').that.deep.equals(new Set([foo])); + expect(events).to.have.property('constructor').that.deep.equals([foo]); }); it('should append handler for existing type', () => { @@ -43,18 +43,20 @@ describe('mitt#', () => { inst.on('foo', foo); inst.on('foo', bar); - expect(events).to.have.property('foo').that.deep.equals(new Set([foo, foo, bar])); + expect(events).to.have.property('foo').that.deep.equals([foo, bar]); }); - it('should normalize case', () => { + it('should NOT normalize case', () => { let foo = () => {}; inst.on('FOO', foo); inst.on('Bar', foo); inst.on('baz:baT!', foo); - expect(events).to.have.property('foo').that.deep.equals(new Set([foo])); - expect(events).to.have.property('bar').that.deep.equals(new Set([foo])); - expect(events).to.have.property('baz:bat!').that.deep.equals(new Set([foo])); + expect(events).to.have.property('FOO').that.deep.equals([foo]); + expect(events).to.not.have.property('foo'); + expect(events).to.have.property('Bar').that.deep.equals([foo]); + expect(events).to.not.have.property('bar'); + expect(events).to.have.property('baz:baT!').that.deep.equals([foo]); }); }); @@ -75,17 +77,19 @@ describe('mitt#', () => { it('should normalize case', () => { let foo = () => {}; - inst.on('foo', foo); - inst.on('bar', foo); + inst.on('FOO', foo); + inst.on('Bar', foo); inst.on('baz:bat!', foo); inst.off('FOO', foo); inst.off('Bar', foo); inst.off('baz:baT!', foo); - expect(events).to.have.property('foo').that.is.empty; - expect(events).to.have.property('bar').that.is.empty; - expect(events).to.have.property('baz:bat!').that.is.empty; + expect(events).to.have.property('FOO').that.is.empty; + expect(events).to.not.have.property('foo'); + expect(events).to.have.property('Bar').that.is.empty; + expect(events).to.not.have.property('bar'); + expect(events).to.have.property('baz:baT!').that.is.empty; }); }); @@ -107,27 +111,31 @@ describe('mitt#', () => { inst.emit('foo', event); }); - it('should invoke handler with multiple arguments', () => { - inst.on('foo', (aaa, bbb, ccc) => { + it('should invoke handler with multiple (max 2) arguments', () => { + inst.on('foo', (aaa, bbb) => { expect(aaa).to.be.equal(111); expect(bbb).to.be.equal(222); - expect(ccc).to.be.equal(333); }); - inst.emit('foo', 111, 222, 333); + inst.emit('foo', 111, 222); }); - it('should ignore case', () => { + it('should NOT ignore case', () => { let foo = spy(), + bar = spy(), num = 123; - events.foo = [foo]; + events.Foo = [foo]; + events.FOO = [bar]; inst.emit('FOO', num); inst.emit('Foo', num); - let args = foo.args[0]; + let args1 = foo.args[0]; + let args2 = bar.args[0]; - expect(foo).to.have.been.calledTwice; - expect(args).to.be.deep.equal([num, undefined, undefined]); + expect(foo).to.have.been.calledOnce; + expect(bar).to.have.been.calledOnce; + expect(args1).to.be.deep.equal([num, undefined]); + expect(args2).to.be.deep.equal([num, undefined]); }); it('should invoke * handlers', () => { @@ -142,8 +150,8 @@ describe('mitt#', () => { args2 = star.args[1]; expect(star).to.have.been.calledTwice; - expect(args1).to.deep.equal(['foo', aa, undefined, undefined]); - expect(args2).to.deep.equal(['bar', aa, undefined, undefined]); + expect(args1).to.deep.equal(['foo', aa, undefined]); + expect(args2).to.deep.equal(['bar', aa, undefined]); }); }); }); |
