Skip to content

Commit 91ac56f

Browse files
committed
add tests
1 parent 3fdb0aa commit 91ac56f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Tests/Shared/TestCase+Extensions.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@ extension XCTestCase {
55
try closure()
66
}
77

8+
func given(_ description: String, closure: () async throws -> Void) async rethrows {
9+
try await closure()
10+
}
11+
812
func when(_ description: String, closure: () throws -> Void) rethrows {
913
try closure()
1014
}
1115

16+
func when(_ description: String, closure: () async throws -> Void) async rethrows {
17+
try await closure()
18+
}
19+
1220
func then(_ description: String, closure: () throws -> Void) rethrows {
1321
try closure()
1422
}
23+
24+
func then(_ description: String, closure: () async throws -> Void) async rethrows {
25+
try await closure()
26+
}
1527
}

Tests/iOS/Tests/Storage/AsyncStorageTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ final class AsyncStorageTests: XCTestCase {
3636
wait(for: [expectation], timeout: 1)
3737
}
3838

39+
func testSetObject() async throws {
40+
try await storage.setObject(user, forKey: "user")
41+
let cachedUser = try await storage.object(forKey: "user")
42+
43+
XCTAssertEqual(cachedUser, self.user)
44+
}
45+
3946
func testRemoveAll() {
4047
let intStorage = storage.transform(transformer: TransformerFactory.forCodable(ofType: Int.self))
4148
let expectation = self.expectation(description: #function)
@@ -62,4 +69,24 @@ final class AsyncStorageTests: XCTestCase {
6269

6370
wait(for: [expectation], timeout: 1)
6471
}
72+
73+
func testRemoveAll() async throws {
74+
let intStorage = storage.transform(transformer: TransformerFactory.forCodable(ofType: Int.self))
75+
try await given("add a lot of objects") {
76+
for i in 0 ..< 100 {
77+
try await intStorage.setObject(i, forKey: "key-\(i)")
78+
}
79+
}
80+
81+
try await when("remove all") {
82+
try await intStorage.removeAll()
83+
}
84+
85+
await then("all are removed") {
86+
do {
87+
_ = try await intStorage.objectExists(forKey: "key-99")
88+
XCTFail()
89+
} catch {}
90+
}
91+
}
6592
}

0 commit comments

Comments
 (0)