changes from review
This commit is contained in:
parent
75a117e4e2
commit
933c7330a5
2 changed files with 21 additions and 16 deletions
|
@ -20,7 +20,6 @@ class CallbacksRegistry {
|
|||
const regexp = /at (.*)/gi
|
||||
const stackString = (new Error()).stack
|
||||
|
||||
let ref
|
||||
let filenameAndLine
|
||||
let match
|
||||
|
||||
|
@ -29,7 +28,7 @@ class CallbacksRegistry {
|
|||
if (location.includes('native')) continue
|
||||
if (location.includes('electron.asar')) continue
|
||||
|
||||
ref = /([^/^)]*)\)?$/gi.exec(location)
|
||||
const ref = /([^/^)]*)\)?$/gi.exec(location)
|
||||
filenameAndLine = ref[1]
|
||||
break
|
||||
}
|
||||
|
@ -40,7 +39,7 @@ class CallbacksRegistry {
|
|||
}
|
||||
|
||||
get (id) {
|
||||
return this.callbacks[id] != null ? this.callbacks[id] : function () {}
|
||||
return this.callbacks[id] || function () {}
|
||||
}
|
||||
|
||||
apply (id, ...args) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const assert = require('assert')
|
||||
const {assert} = require('chai')
|
||||
const {CallbacksRegistry} = require('electron')
|
||||
|
||||
describe('CallbacksRegistry module', () => {
|
||||
describe.only('CallbacksRegistry module', () => {
|
||||
let registry = null
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -10,33 +10,39 @@ describe('CallbacksRegistry module', () => {
|
|||
|
||||
it('adds a callback to the registry', () => {
|
||||
const cb = () => [1, 2, 3, 4, 5]
|
||||
const id = registry.add(cb)
|
||||
assert.equal(id, 1)
|
||||
const key = registry.add(cb)
|
||||
|
||||
assert.exists(key)
|
||||
})
|
||||
|
||||
it('returns a specified callback if it is in the registry', () => {
|
||||
const cb = () => [1, 2, 3, 4, 5]
|
||||
registry.add(cb)
|
||||
const key = registry.add(cb)
|
||||
const callback = registry.get(key)
|
||||
|
||||
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 () {}')
|
||||
|
||||
assert.isFunction(callback)
|
||||
})
|
||||
|
||||
it('removes a callback to the registry', () => {
|
||||
const cb = () => [1, 2, 3, 4, 5]
|
||||
const id = registry.add(cb)
|
||||
assert.equal(id, 1)
|
||||
const key = registry.add(cb)
|
||||
|
||||
assert.exists(key)
|
||||
|
||||
const beforeCB = registry.get(key)
|
||||
|
||||
const beforeCB = registry.get(1)
|
||||
assert.equal(beforeCB.toString(), cb.toString())
|
||||
|
||||
registry.remove(1)
|
||||
const afterCB = registry.get(1)
|
||||
assert.equal(afterCB.toString(), 'function () {}')
|
||||
registry.remove(key)
|
||||
const afterCB = registry.get(key)
|
||||
|
||||
assert.isFunction(afterCB)
|
||||
assert.notEqual(afterCB.toString(), cb.toString())
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue