added the start of an experimental browser API so we can access the browser environment from a typesafe kotlin API which can be implemented on a JVM (e.g. with JavaFX) or compiled natively to JS to reuse the browser global variables
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package test.browser
|
||||
|
||||
import kotlin.dom.*
|
||||
import kotlin.browser.*
|
||||
|
||||
import kotlin.test.*
|
||||
import org.junit.Test as test
|
||||
|
||||
class BrowserTest {
|
||||
|
||||
test fun accessBrowserDOM() {
|
||||
registerBrowserPage()
|
||||
|
||||
val h1 = document["h1"].first()
|
||||
assertEquals("Hello World!", h1.text)
|
||||
}
|
||||
|
||||
protected fun registerBrowserPage() {
|
||||
// lets simulate being a browser registering its DOM
|
||||
val doc = createDocument()
|
||||
doc.addElement("html") {
|
||||
addElement("body") {
|
||||
addElement("h1") {
|
||||
addText("Hello World!")
|
||||
}
|
||||
addElement("p") {
|
||||
addText("This is some text content")
|
||||
}
|
||||
}
|
||||
}
|
||||
document = doc
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user