-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathWebAPIKitTests.swift
43 lines (36 loc) · 1.25 KB
/
WebAPIKitTests.swift
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
import Foundation
import JavaScriptKit
import WebAPIKit
import XCTest
final class WebAPIKitTests: XCTestCase {
func testQuerySelector() {
let document = globalThis.document
let button = document.createElement(localName: "button")
button.textContent = "Hello, world!"
_ = document.querySelector(selectors: "body")?.appendChild(node: button)
let queriedButton = document.querySelector(selectors: "body button")
XCTAssertEqual(queriedButton?.textContent, "Hello, world!")
}
func testDataToTypedArray() {
let array: [UInt8] = [1, 2, 3, 4, 5]
let data = Data(array)
let typedArray = JSTypedArray(data)
typedArray.withUnsafeBytes {
XCTAssertEqual($0.count, data.count)
for index in $0.indices {
XCTAssertEqual(array[index], $0[index])
}
}
}
func testTypedArrayToData() {
let array: [UInt8] = [1, 2, 3, 4, 5]
let typedArray = JSTypedArray(array)
let data = Data(typedArray.buffer)
typedArray.withUnsafeBytes {
XCTAssertEqual($0.count, data.count)
for index in $0.indices {
XCTAssertEqual(array[index], $0[index])
}
}
}
}