-
Notifications
You must be signed in to change notification settings - Fork 12
/
PostListViewControllerTests.swift
45 lines (36 loc) · 1.18 KB
/
PostListViewControllerTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// PostListViewControllerTests.swift
// SwiftMVVMDemoTests
//
// Created by Rushi Sangani on 06/12/2023.
//
import XCTest
@testable import SwiftMVVMDemo
final class PostListViewControllerTests: XCTestCase {
var postListVC: PostListViewController!
var viewModel: PostListViewModel!
override func setUpWithError() throws {
viewModel = PostListViewModel(postService: MockPostService())
postListVC = PostListViewController(viewModel: viewModel)
}
override func tearDownWithError() throws {
postListVC = nil
viewModel = nil
}
func testPostListVCShowPostsInTableView() throws {
let expectation = XCTestExpectation(description: "TableView has data")
postListVC.loadView()
postListVC.setupObservers()
Task {
do {
try await viewModel.loadPosts()
expectation.fulfill()
}
catch {
XCTFail("Expected viewmodel should load posts")
}
}
wait(for: [expectation], timeout: 3)
XCTAssertEqual(viewModel.posts.count, postListVC.tableView.numberOfRows(inSection: 0))
}
}