Skip to content

Commit b314db8

Browse files
committed
Add a basic test for JSValueDecoder
1 parent 3cd8c26 commit b314db8

File tree

1 file changed

+22
-0
lines changed
  • IntegrationTests/TestSuites/Sources/PrimaryTests

1 file changed

+22
-0
lines changed

IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,5 +804,27 @@ try test("Hashable Conformance") {
804804
try expectEqual(firstHash, secondHash)
805805
}
806806

807+
struct AnimalStruct: Decodable {
808+
let name: String
809+
let age: Int
810+
let isCat: Bool
811+
}
812+
813+
try test("JSValueDecoder") {
814+
let Animal = JSObject.global.Animal.function!
815+
let tama = try Animal.throws.new("Tama", 3, true)
816+
let decoder = JSValueDecoder()
817+
let decodedTama = try decoder.decode(AnimalStruct.self, from: tama.jsValue)
818+
819+
try expectEqual(decodedTama.name, tama.name.string)
820+
try expectEqual(decodedTama.name, "Tama")
821+
822+
try expectEqual(decodedTama.age, tama.age.number.map(Int.init))
823+
try expectEqual(decodedTama.age, 3)
824+
825+
try expectEqual(decodedTama.isCat, tama.isCat.boolean)
826+
try expectEqual(decodedTama.isCat, true)
827+
}
828+
807829

808830
Expectation.wait(expectations)

0 commit comments

Comments
 (0)