diff --git a/src/core/application.ts b/src/core/application.ts index b8b92715..5eaa9a1d 100644 --- a/src/core/application.ts +++ b/src/core/application.ts @@ -79,7 +79,10 @@ export class Application implements ErrorHandler { getControllerForElementAndIdentifier(element: Element, identifier: string): Controller | null { const context = this.router.getContextForElementAndIdentifier(element, identifier) - return context ? context.controller : null + if (context) return context.controller + + this.logDebugActivity(identifier, "controller not found", { element }) + return null } // Error handling diff --git a/src/tests/modules/core/application_tests.ts b/src/tests/modules/core/application_tests.ts index 8cee672f..b7a6046f 100644 --- a/src/tests/modules/core/application_tests.ts +++ b/src/tests/modules/core/application_tests.ts @@ -45,6 +45,24 @@ export default class ApplicationTests extends ApplicationTestCase { this.assert.ok(this.controllers[0] instanceof BController) } + "test Application#getControllerForElementAndIdentifier logs debug activity when controller not found"() { + this.application.load(this.definitions) + + const logCalls: { identifier: string; functionName: string; detail: { element?: Element } }[] = [] + this.application.logDebugActivity = (identifier, functionName, detail = {}) => { + logCalls.push({ identifier, functionName, detail }) + } + + const element = this.fixtureElement.querySelector("[data-controller='a']")! + const result = this.application.getControllerForElementAndIdentifier(element, "nonexistent") + + this.assert.equal(result, null) + this.assert.equal(logCalls.length, 1) + this.assert.equal(logCalls[0].identifier, "nonexistent") + this.assert.equal(logCalls[0].functionName, "controller not found") + this.assert.equal(logCalls[0].detail.element, element) + } + get controllers() { return this.application.controllers as LogController[] }