test: tsify callbacks-registry spec (#19606)

This commit is contained in:
Jeremy Apthorp 2019-08-04 17:46:58 -07:00 committed by Cheng Zhao
parent 45e452557b
commit f08be2162a

View file

@ -0,0 +1,44 @@
import { expect } from 'chai'
import { CallbacksRegistry } from '../lib/renderer/callbacks-registry'
describe('CallbacksRegistry module', () => {
let registry: CallbacksRegistry
beforeEach(() => {
registry = new CallbacksRegistry()
})
it('adds a callback to the registry', () => {
const cb = () => [1, 2, 3, 4, 5]
const key = registry.add(cb)
expect(key).to.exist('key')
})
it('returns a specified callback if it is in the registry', () => {
const cb = () => [1, 2, 3, 4, 5]
const key = registry.add(cb)
expect(key).to.exist('key')
const callback = registry.get(key!)
expect(callback.toString()).equal(cb.toString())
})
it('returns an empty function if the cb doesnt exist', () => {
const callback = registry.get(1)
expect(callback).to.be.a('function')
})
it('removes a callback to the registry', () => {
const cb = () => [1, 2, 3, 4, 5]
const key = registry.add(cb)
expect(key).to.exist('key')
registry.remove(key!)
const afterCB = registry.get(key!)
expect(afterCB).to.be.a('function')
expect(afterCB.toString()).to.not.equal(cb.toString())
})
})