diff --git a/src/core/application.ts b/src/core/application.ts index 74a451fe..b8b92715 100644 --- a/src/core/application.ts +++ b/src/core/application.ts @@ -17,7 +17,7 @@ export class Application implements ErrorHandler { debug = false static start(element?: Element, schema?: Schema): Application { - const application = new Application(element, schema) + const application = new this(element, schema) application.start() return application } diff --git a/src/tests/modules/core/extending_application_tests.ts b/src/tests/modules/core/extending_application_tests.ts new file mode 100644 index 00000000..a9cd7f6c --- /dev/null +++ b/src/tests/modules/core/extending_application_tests.ts @@ -0,0 +1,51 @@ +import { Application } from "../../../core/application" +import { DOMTestCase } from "../../cases/dom_test_case" +import { ActionDescriptorFilter } from "src/core/action_descriptor" + +const mockCallback: { (label: string): void; lastCall: string | null } = (label: string) => { + mockCallback.lastCall = label +} +mockCallback.lastCall = null + +class TestApplicationWithCustomBehavior extends Application { + registerActionOption(name: string, filter: ActionDescriptorFilter): void { + mockCallback(`registerActionOption:${name}`) + super.registerActionOption(name, filter) + } +} + +export default class ExtendingApplicationTests extends DOMTestCase { + application!: Application + + async runTest(testName: string) { + try { + // use the documented way to start & reference only the returned application instance + this.application = TestApplicationWithCustomBehavior.start(this.fixtureElement) + await super.runTest(testName) + } finally { + this.application.stop() + } + } + + async setup() { + mockCallback.lastCall = null + } + + async teardown() { + mockCallback.lastCall = null + } + + async "test extended class method is supported when using MyApplication.start()"() { + this.assert.equal(mockCallback.lastCall, null) + + const mockTrue = () => true + this.application.registerActionOption("kbd", mockTrue) + this.assert.equal(this.application.actionDescriptorFilters["kbd"], mockTrue) + this.assert.equal(mockCallback.lastCall, "registerActionOption:kbd") + + const mockFalse = () => false + this.application.registerActionOption("xyz", mockFalse) + this.assert.equal(this.application.actionDescriptorFilters["xyz"], mockFalse) + this.assert.equal(mockCallback.lastCall, "registerActionOption:xyz") + } +}