2017-11-16 18:39:07 +00:00
|
|
|
const {assert} = require('chai')
|
2017-11-16 05:04:33 +00:00
|
|
|
const {CallbacksRegistry} = require('electron')
|
|
|
|
|
2017-11-16 18:39:07 +00:00
|
|
|
describe.only('CallbacksRegistry module', () => {
|
2017-11-16 05:04:33 +00:00
|
|
|
let registry = null
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
registry = new CallbacksRegistry()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('adds a callback to the registry', () => {
|
|
|
|
const cb = () => [1, 2, 3, 4, 5]
|
2017-11-16 18:39:07 +00:00
|
|
|
const key = registry.add(cb)
|
|
|
|
|
|
|
|
assert.exists(key)
|
2017-11-16 05:04:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('returns a specified callback if it is in the registry', () => {
|
|
|
|
const cb = () => [1, 2, 3, 4, 5]
|
2017-11-16 18:39:07 +00:00
|
|
|
const key = registry.add(cb)
|
|
|
|
const callback = registry.get(key)
|
2017-11-16 05:04:33 +00:00
|
|
|
|
|
|
|
assert.equal(callback.toString(), cb.toString())
|
|
|
|
})
|
|
|
|
|
|
|
|
it('returns an empty function if the cb doesnt exist', () => {
|
|
|
|
const callback = registry.get(1)
|
2017-11-16 18:39:07 +00:00
|
|
|
|
|
|
|
assert.isFunction(callback)
|
2017-11-16 05:04:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('removes a callback to the registry', () => {
|
|
|
|
const cb = () => [1, 2, 3, 4, 5]
|
2017-11-16 18:39:07 +00:00
|
|
|
const key = registry.add(cb)
|
|
|
|
|
|
|
|
assert.exists(key)
|
|
|
|
|
|
|
|
const beforeCB = registry.get(key)
|
2017-11-16 05:04:33 +00:00
|
|
|
|
|
|
|
assert.equal(beforeCB.toString(), cb.toString())
|
|
|
|
|
2017-11-16 18:39:07 +00:00
|
|
|
registry.remove(key)
|
|
|
|
const afterCB = registry.get(key)
|
|
|
|
|
|
|
|
assert.isFunction(afterCB)
|
|
|
|
assert.notEqual(afterCB.toString(), cb.toString())
|
2017-11-16 05:04:33 +00:00
|
|
|
})
|
2017-11-16 05:08:18 +00:00
|
|
|
})
|