Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the Application.start static method uses overridden class #603

Merged
merged 1 commit into from Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/application.ts
Expand Up @@ -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
}
Expand Down
51 changes: 51 additions & 0 deletions 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")
}
}