Skip to content

Commit 740ee09

Browse files
committed
Add test to DefaultFalse when key is not available
1 parent bef95eb commit 740ee09

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Tests/BetterCodableTests/DefaultFalseTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ class DefaultFalseTests: XCTestCase {
1111
let fixture = try JSONDecoder().decode(Fixture.self, from: jsonData)
1212
XCTAssertEqual(fixture.truthy, false)
1313
}
14+
15+
func testDecodingKeyNotPresentDefaultsToFalse() throws {
16+
let jsonData = #"{}"#.data(using: .utf8)!
17+
let fixture = try JSONDecoder().decode(Fixture.self, from: jsonData)
18+
XCTAssertEqual(fixture.truthy, false)
19+
}
1420

1521
func testEncodingDecodedFailableArrayDefaultsToEmptyArray() throws {
1622
let jsonData = #"{ "truthy": null }"#.data(using: .utf8)!

0 commit comments

Comments
 (0)