0

I am trying to call a completion block in a unit test but it never reaches. Here is the code:

[vc configureRecorder:^{
    NSLog(@"Completion...");
}];

This is the method:

-(void)configureRecorder:(void(^)(void))callback {
    NSLog(@"Method");
}
Niall Kiddle
  • 1,477
  • 1
  • 16
  • 35
  • 1
    I assume you did call `callback()` somewhere inside of @"method"? If you didn't then why do you expect it to be called. If you did - how? Mind that unit tests executed on main thread, and do not waiting for anything asynchronous to happened in another threads. If it is a case - take a look on XCTestExpectation https://developer.apple.com/documentation/xctest/xctestcase/1500899-expectation – MichaelV Feb 27 '18 at 19:59

1 Answers1

3

You need to call the completion block at the end of your method. like this:

-(void)configureRecorder:(void(^)(void))callback {
    //@"Method"
    callback()
}
Enrique Bermúdez
  • 1,740
  • 2
  • 11
  • 25