/
extending_application_tests.ts
51 lines (42 loc) · 1.71 KB
/
extending_application_tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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")
}
}