2018-06-17 15:08:17 -07:00
|
|
|
const chai = require('chai')
|
|
|
|
const dirtyChai = require('dirty-chai')
|
|
|
|
|
2018-09-14 02:10:51 +10:00
|
|
|
const { expect } = chai
|
2018-06-17 15:08:17 -07:00
|
|
|
chai.use(dirtyChai)
|
|
|
|
|
2018-08-31 20:29:00 +02:00
|
|
|
const CallbacksRegistry = require('../lib/renderer/callbacks-registry')
|
2017-11-16 00:04:33 -05:00
|
|
|
|
2017-11-16 14:51:24 -05:00
|
|
|
describe('CallbacksRegistry module', () => {
|
2017-11-16 00:04:33 -05: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 13:39:07 -05:00
|
|
|
const key = registry.add(cb)
|
|
|
|
|
2018-06-17 15:08:17 -07:00
|
|
|
expect(key).to.exist()
|
2017-11-16 00:04:33 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('returns a specified callback if it is in the registry', () => {
|
|
|
|
const cb = () => [1, 2, 3, 4, 5]
|
2017-11-16 13:39:07 -05:00
|
|
|
const key = registry.add(cb)
|
|
|
|
const callback = registry.get(key)
|
2017-11-16 00:04:33 -05:00
|
|
|
|
2018-06-17 15:08:17 -07:00
|
|
|
expect(callback.toString()).equal(cb.toString())
|
2017-11-16 00:04:33 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('returns an empty function if the cb doesnt exist', () => {
|
|
|
|
const callback = registry.get(1)
|
2017-11-16 13:39:07 -05:00
|
|
|
|
2018-06-17 15:08:17 -07:00
|
|
|
expect(callback).to.be.a('function')
|
2017-11-16 00:04:33 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('removes a callback to the registry', () => {
|
|
|
|
const cb = () => [1, 2, 3, 4, 5]
|
2017-11-16 13:39:07 -05:00
|
|
|
const key = registry.add(cb)
|
|
|
|
|
|
|
|
registry.remove(key)
|
|
|
|
const afterCB = registry.get(key)
|
|
|
|
|
2018-06-17 15:08:17 -07:00
|
|
|
expect(afterCB).to.be.a('function')
|
|
|
|
expect(afterCB.toString()).to.not.equal(cb.toString())
|
2017-11-16 00:04:33 -05:00
|
|
|
})
|
2017-11-16 00:08:18 -05:00
|
|
|
})
|