Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UIViewControllerSpec
import Quick
import Nimble
@testable import <#AppModule#>
class Mock<#Name#>ViewModel: <#Name#>ViewModel {
var <#func#>Count = 0
override func <#func#>() {
<#func#>Count++
super.<#func#>()
}
}
class <#Name#>ViewControllerSpec: QuickSpec {
override func spec() {
describe("<#Name#>") {
var sut: <#Name#>ViewController!
var viewModel: <#Name#>ViewModel!
beforeEach {
viewModel = Mock<#Name#>ViewModel()
sut = <#Name#>ViewController(viewModel: viewModel)
}
afterEach {
sut = nil
viewModel = nil
}
context("when view loads") {
beforeEach {
sut.viewDidLoad()
}
it("has appropriate title") {
expect(sut.title).to(equal(viewModel.title))
expect(sut.navigationItem.title).to(equal(viewModel.title))
}
it("has left button") {
expect(sut.navigationItem.leftBarButtonItem).to(beAKindOf(UIBarButtonItem))
expect(sut.navigationItem.leftBarButtonItem?.enabled).to(beTrue())
}
it("has right button") {
expect(sut.navigationItem.rightBarButtonItem).to(beAKindOf(UIBarButtonItem))
expect(sut.navigationItem.rightBarButtonItem?.enabled).to(beTrue())
}
it("has a tableView") {
expect(sut.tableView).to(beAKindOf(UITableView))
expect(sut.tableView.superview).to(equal(sut.view))
}
it("table view has 1 section") {
expect(sut.tableView.numberOfSections).to(equal(1))
}
it("table view shows list from viewModel") {
expect(sut.tableView.numberOfRowsInSection(0)).to(equal(viewModel.<#count#>))
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.