Created
August 9, 2020 15:36
-
-
Save Bradysm/8128531745ba4c85601d297b9b7333f9 to your computer and use it in GitHub Desktop.
This file contains 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
import XCTest | |
@testable import Mocking | |
class MockingTests: XCTestCase { | |
let username = "testusername" | |
/// mocked service for sending message | |
var mockedMessageService = MockedMessageService() | |
var chatRoomViewModel: ChatRoomViewModel! | |
// initialization for each test | |
override func setUpWithError() throws { | |
// Put setup code here. This method is called before the invocation of each test method in the class. | |
self.chatRoomViewModel = ChatRoomViewModel(messagingService: mockedMessageService, username: username) | |
} | |
/** | |
Tests to the sending of a valid message to the mocked service | |
Once completed, the error message should still be nil and the typed message should be set to empty | |
*/ | |
func testSendingValidMessage() { | |
// write a message and then call send | |
self.chatRoomViewModel.typedMessage = "Here is a valid message" | |
self.chatRoomViewModel.sendMessage() | |
// assert that the error message was updated | |
XCTAssertNil(self.chatRoomViewModel.errorMessage) | |
// assert that the typed message was cleared | |
XCTAssertTrue(self.chatRoomViewModel.typedMessage.isEmpty) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment