Skip to content

Commit

Permalink
Add coverage to catch inconsistency exception
Browse files Browse the repository at this point in the history
Summary:
Added a unit test to cover the inconsistency exception catch we added to capture the crashes caused by the new collection view behaviour in iOS 16.4.

The test deliberately puts the collection view state and the model state out of alignment, and then tests that the exception correctly occurs as expected.

Reviewed By: fabiomassimo

Differential Revision: D50072956

fbshipit-source-id: 4097cc0451d55d1a148156c783fe42654821113c
  • Loading branch information
TimOliver authored and facebook-github-bot committed Oct 12, 2023
1 parent 2bdbc12 commit a18565b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Tests/IGListTransactionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,21 @@ - (void)test_withReloadTransaction_thatAllStubbedMethodsNoOpCorrectly {
[transaction reloadSections:[NSIndexSet indexSet]];
}

- (void)test_withIncorrectUpdatesState_thatInconsistencyExceptionIsCaught {
_config.allowsBackgroundDiffing = NO;
__weak __typeof__(self) weakSelf = self;
self.applySectionDataBlock = ^(IGListTransitionData *data) {
[weakSelf.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathWithIndex:0]]];
};
BOOL exceptionWasHandled = NO;
IGListBatchUpdateTransaction *batchUpdateTransaction = [self makeBatchUpdateTransaction];
@try {
[batchUpdateTransaction begin];
} @catch (NSException *exception) {
exceptionWasHandled = YES;
XCTAssertTrue([exception.name isEqualToString:@"NSInternalInconsistencyException"]);
}
XCTAssertTrue(exceptionWasHandled);
}

@end

0 comments on commit a18565b

Please sign in to comment.