Avatar
omochimetaru 4/9/2024 4:34 PM
func testState() throws { struct Content: Component { @State var count = 0 func render() -> Node { return div { "\(count)" button( listeners: [ "click": Function { (ev) in count += 1 } ] ) } } } let body = try document.createElement("body") let root = ReactRoot(element: body) root.render( node: Content() ) XCTAssertPrint(body, """ <body> <div> 0 <button /> </div> </body> """) let btn: JSHTMLElement = try XCTUnwrap( root.root? .find { $0.tagElement?.tagName == "button" }? .dom?.asHTMLElement() ) try btn.click() XCTAssertPrint(body, """ <body> <div> 1 <button /> </div> </body> """) } ちょっとそれっぽくなってきた(↑このテストが通った) (edited)
🎉 3