-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2141 from Orange-OpenSource/AddEventBusUnitTest
add EventBus unit test
- Loading branch information
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import EventBus from '../../src/core/EventBus'; | ||
|
||
const chai = require('chai'); | ||
const sinon = require('sinon'); | ||
const expect = chai.expect; | ||
const assert = chai.assert; | ||
|
||
const context = {}; | ||
const eventBus = EventBus(context).getInstance(); | ||
|
||
describe('EventBus', function () { | ||
|
||
it("should throw an exception when attempting to register the on callback with an undefined type", function () { | ||
expect(eventBus.on.bind(eventBus)).to.throw('event type cannot be null or undefined'); | ||
}); | ||
|
||
it("should throw an exception when attempting to register the on callback with an undefined listener", function () { | ||
expect(eventBus.on.bind(eventBus, 'EVENT_TEST')).to.throw('listener must be a function: undefined'); | ||
}); | ||
|
||
it("should throw an exception when attempting to trigger a 'type' payload parameter", function () { | ||
const spy = sinon.spy(); | ||
|
||
eventBus.on('EVENT_TEST', spy); | ||
|
||
expect(eventBus.trigger.bind(eventBus, 'EVENT_TEST', { type:{}})).to.throw('\'type\' is a reserved word for event dispatching'); | ||
}); | ||
|
||
it("should respect priority parameter in order to notify the different listeners", function () { | ||
const spy = sinon.spy(); | ||
const spy2 = sinon.spy(); | ||
|
||
eventBus.on('EVENT_TEST', spy); | ||
eventBus.on('EVENT_TEST', spy2, this, EventBus.EVENT_PRIORITY_HIGH); | ||
|
||
eventBus.trigger('EVENT_TEST', {}); | ||
|
||
assert.equal(spy.calledOnce, true); | ||
assert.equal(spy2.calledOnce, true); | ||
assert.equal(spy2.calledBefore(spy), true); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters