diff --git a/spec/command-registry-spec.coffee b/spec/command-registry-spec.coffee index b92d3e6b0..0a8cafa6b 100644 --- a/spec/command-registry-spec.coffee +++ b/spec/command-registry-spec.coffee @@ -158,6 +158,26 @@ describe "CommandRegistry", -> addError = error expect(addError.message).toContain(badSelector) + it "throws an error when called with a non-function callback and selector target", -> + badCallback = null + addError = null + + try + registry.add '.selector', 'foo:bar', badCallback + catch error + addError = error + expect(addError.message).toContain("Can't register a command with non-function callback.") + + it "throws an error when called with an non-function callback and object target", -> + badCallback = null + addError = null + + try + registry.add document.body, 'foo:bar', badCallback + catch error + addError = error + expect(addError.message).toContain("Can't register a command with non-function callback.") + describe "::findCommands({target})", -> it "returns commands that can be invoked on the target or its ancestors", -> registry.add '.parent', 'namespace:command-1', -> diff --git a/src/command-registry.coffee b/src/command-registry.coffee index 72098eda0..870093e2f 100644 --- a/src/command-registry.coffee +++ b/src/command-registry.coffee @@ -92,6 +92,9 @@ class CommandRegistry disposable.add @add(target, commandName, callback) return disposable + if typeof callback isnt 'function' + throw new Error("Can't register a command with non-function callback.") + if typeof target is 'string' validateSelector(target) @addSelectorBasedListener(target, commandName, callback)