diff --git a/platform/darwin/test/MGLOfflineStorageTests.m b/platform/darwin/test/MGLOfflineStorageTests.m index 0661a58ce..c2a8e152d 100644 --- a/platform/darwin/test/MGLOfflineStorageTests.m +++ b/platform/darwin/test/MGLOfflineStorageTests.m @@ -13,12 +13,15 @@ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - [self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { + XCTestExpectation *expectation = [self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue]; return changeKind = NSKeyValueChangeSetting; }]; - - [self waitForExpectationsWithTimeout:1 handler:nil]; + if ([MGLOfflineStorage sharedOfflineStorage].packs) { + [expectation fulfill]; + } else { + [self waitForExpectationsWithTimeout:1 handler:nil]; + } XCTAssertNotNil([MGLOfflineStorage sharedOfflineStorage].packs, @"Shared offline storage object should have a non-nil collection of packs by this point."); });