Skip to content

Instantly share code, notes, and snippets.

@Bradysm
Created August 9, 2020 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bradysm/8128531745ba4c85601d297b9b7333f9 to your computer and use it in GitHub Desktop.
Save Bradysm/8128531745ba4c85601d297b9b7333f9 to your computer and use it in GitHub Desktop.
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