You're right. To test reset you need to call reset , not internal methods.
At the same time, reset is currently written in such a way that makes it unstable. The reason you can easily test other standalone methods is the callback argument, which accepts.
I would recommend that you rewrite reset to allow two optional callbacks as follows:
typealias Callback = () -> () func reset( homeDataCallback: @escaping Callback? = nil, anythingElseCallback: @escaping Callback? = nil) { initializeAnythingElse() { anythingElseCallback?() } initializeHomeData() { homeDataCallback?() } }
Note that this change allows you to be notified in async when these two internal calls are completed.
Now your test method should be written using some kind of synchronization primitive, since a logical reset is performed only when both the home data and everything else is done, and their callbacks are called.
There are many ways to achieve this, but I will show you the semaphore approach:
func testReset() { let expectation = expectation(description: "reset() completes within some duration")
Note that all of this change is required to allow you to test the reset call. Your function signature allows you to write reset() as current in existing code, as it has optional arguments that have default values ββfor default values.
source share