electron/spec/api-callbacks-registry-spec.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-11-16 05:04:33 +00:00
const assert = require('assert')
const {CallbacksRegistry} = require('electron')
2017-11-16 13:15:56 +00:00
describe('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]
const id = registry.add(cb)
assert.equal(id, 1)
})
it('returns a specified callback if it is in the registry', () => {
const cb = () => [1, 2, 3, 4, 5]
registry.add(cb)
const callback = registry.get(1)
assert.equal(callback.toString(), cb.toString())
})
it('returns an empty function if the cb doesnt exist', () => {
const callback = registry.get(1)
assert.equal(callback.toString(), 'function () {}')
})
it('removes a callback to the registry', () => {
const cb = () => [1, 2, 3, 4, 5]
const id = registry.add(cb)
assert.equal(id, 1)
const beforeCB = registry.get(1)
assert.equal(beforeCB.toString(), cb.toString())
registry.remove(1)
const afterCB = registry.get(1)
assert.equal(afterCB.toString(), 'function () {}')
})
2017-11-16 05:08:18 +00:00
})