forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi-callbacks-registry-spec.js
47 lines (34 loc) · 1.13 KB
/
api-callbacks-registry-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const { expect } = chai
chai.use(dirtyChai)
const CallbacksRegistry = require('../lib/renderer/callbacks-registry')
describe('CallbacksRegistry module', () => {
let registry = null
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()
})
it('returns a specified callback if it is in the registry', () => {
const cb = () => [1, 2, 3, 4, 5]
const key = registry.add(cb)
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)
registry.remove(key)
const afterCB = registry.get(key)
expect(afterCB).to.be.a('function')
expect(afterCB.toString()).to.not.equal(cb.toString())
})
})