Skip to content

Instantly share code, notes, and snippets.

@KhayalSuleymani
Created October 16, 2024 12:57
Show Gist options
  • Save KhayalSuleymani/d89848f2635e4273707169c3267bfd84 to your computer and use it in GitHub Desktop.
Save KhayalSuleymani/d89848f2635e4273707169c3267bfd84 to your computer and use it in GitHub Desktop.
Views memory leak tests
@testable import Quick
@testable import Nimble
@testable import Common
@testable import SpecLeaks
class ViewControllersTests: QuickSpec {
override class func spec() {
describe("My base represented views on common target...") {
describe("call view events when your viewmodel subscribe your views events by .render(state:)") {
it("must not leak") {
// given
let m = MockViewItem()
let v1 = LeakTest { View1() }
let v2 = LeakTest { View2() }
let v3 = LeakTest { View3() }
let v4 = LeakTest { View4() }
// when
let events: (View4) -> () = { v in
v.didLoad { (v) in
v.render(state: .loading(m))
}.didAppear { v in
v.render(state: .loaded(m))
}.willAppear { v in
v.render(state: .reload(m))
}
v.viewDidLoad()
v.viewDidAppear(true)
v.viewWillAppear(true)
}
// then
expect(v1).toNot(leak())
expect(v2).toNot(leak())
expect(v3).toNot(leak())
expect(v4).toNot(leak())
expect(v4).toNot(leakWhen(events))
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment