XCTestCase+Await.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <XCTest/XCTest.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. /**
  19. * Force the linker to see these extensions even if compiled without -ObjC.
  20. */
  21. void LoadXCTestCaseAwait();
  22. /**
  23. * FSTVoidErrorBlock is a block that gets an error, if one occurred.
  24. *
  25. * @param error The error if it occurred, or nil.
  26. */
  27. typedef void (^FSTVoidErrorBlock)(NSError *_Nullable error);
  28. @interface XCTestCase (Await)
  29. /**
  30. * Await all outstanding expectations with a reasonable timeout, and if any of them fail, XCTFail
  31. * the test.
  32. */
  33. - (void)awaitExpectations;
  34. /**
  35. * Await a specific expectation with a reasonable timeout. If the expectation fails, XCTFail the
  36. * test.
  37. */
  38. - (void)awaitExpectation:(XCTestExpectation *)expectation;
  39. /**
  40. * Await specific expectations with a reasonable timeout. If the expectation fails, XCTFail the
  41. * test.
  42. */
  43. - (void)awaitExpectations:(NSArray<XCTestExpectation *> *)expectations;
  44. /**
  45. * Returns a reasonable timeout for testing against Firestore.
  46. */
  47. - (double)defaultExpectationWaitSeconds;
  48. /**
  49. * Returns a completion block that fulfills a newly-created expectation with the specified
  50. * name.
  51. */
  52. - (FSTVoidErrorBlock)completionForExpectationWithName:(NSString *)expectationName;
  53. /**
  54. * Returns a completion block that fulfills the given expectation.
  55. */
  56. - (FSTVoidErrorBlock)completionForExpectation:(XCTestExpectation *)expectation;
  57. @end
  58. NS_ASSUME_NONNULL_END