Created
April 18, 2023 19:13
-
-
Save mdb1/cbac7df658d467c8c3e0e8084df49a5e to your computer and use it in GitHub Desktop.
UserPreferencesTests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class UserPreferencesTests: XCTestCase { | |
private var userPreferences: UserPreferences! | |
override func setUp() { | |
super.setUp() | |
let userDefaults = UserDefaults(suiteName: #file) | |
userDefaults?.removePersistentDomain(forName: #file) | |
userPreferences = .init(userDefaults: userDefaults!) | |
} | |
func testSettingAndGettingValue() throws { | |
// Set a value for a key | |
userPreferences[.onBoardingSeen] = true | |
// Get the value for the key and verify it | |
let value: Bool = try XCTUnwrap(userPreferences[.onBoardingSeen]) | |
XCTAssertTrue(value) | |
} | |
func testSettingAndDeletingValue() { | |
// Set a value for a key | |
userPreferences[.onBoardingSeen] = true | |
// Delete the value for the key | |
userPreferences.remove(key: .onBoardingSeen) | |
// Get the value for the key and verify it is nil | |
let value: Bool? = userPreferences[.onBoardingSeen] | |
XCTAssertNil(value) | |
} | |
func testGettingNonExistentValue() { | |
// Get the value for a non-existent key and verify it is nil | |
let value: Bool? = userPreferences[.onBoardingSeen] | |
XCTAssertNil(value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment