Skip to content

Commit

Permalink
Assert on queriedButton not button in the test (#6)
Browse files Browse the repository at this point in the history
The current test was meaningless as we didn't assert on the text content of `queriedButton`.

I've also removed `addEventListener` because it doesn't actually work. The `button` instance is already deallocated by the time that test has finished, so the closure passed to `addEventListener` is released too. We need to find a way to run async tests like this, and I have a few thoughts, but this still needs to be explored.
  • Loading branch information
MaxDesiatov authored Dec 27, 2020
1 parent e4b50a4 commit e45d37f
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions Tests/DOMKitTests/DOMKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ final class DOMKitTests: XCTestCase {
let document = globalThis.document
let button = document.createElement(localName: "button")
button.textContent = "Hello, world!"
button.addEventListener(type: "click") { event in
(event.target as? HTMLElement)?.textContent = "Clicked!"
}
_ = document.querySelector(selectors: "body")?.appendChild(node: button)

let queriedButton = document.querySelector(selectors: "body button")
XCTAssertEqual(button.textContent, "Hello, world!")
XCTAssertEqual(queriedButton?.textContent, "Hello, world!")
}
}

0 comments on commit e45d37f

Please sign in to comment.