Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/core/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/tests/modules/core/application_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}
Expand Down