Check if subnodes where modified during layoutSpecThatFits: (#2164)

This commit is contained in:
Michael Schneider
2016-08-28 16:55:42 -07:00
committed by Adlai Holler
parent 578ac4c48d
commit ba5dc984d7
4 changed files with 72 additions and 0 deletions

View File

@@ -34,4 +34,35 @@
ASXCTAssertEqualSizes(displayNode.calculatedSize, CGSizeMake(100, 100), @"Automatic measurement pass should be happened in layout");
}
#if DEBUG
- (void)testNotAllowAddingSubnodesInLayoutSpecThatFits
{
ASDisplayNode *displayNode = [ASDisplayNode new];
ASDisplayNode *someOtherNode = [ASDisplayNode new];
displayNode.layoutSpecBlock = ^(ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) {
[node addSubnode:someOtherNode];
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsZero child:someOtherNode];
};
XCTAssertThrows([displayNode measure:CGSizeMake(100, 100)], @"Should throw if subnode was added in layoutSpecThatFits:");
}
- (void)testNotAllowModifyingSubnodesInLayoutSpecThatFits
{
ASDisplayNode *displayNode = [ASDisplayNode new];
ASDisplayNode *someOtherNode = [ASDisplayNode new];
[displayNode addSubnode:someOtherNode];
displayNode.layoutSpecBlock = ^(ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) {
[someOtherNode removeFromSupernode];
[node addSubnode:[ASDisplayNode new]];
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsZero child:someOtherNode];
};
XCTAssertThrows([displayNode measure:CGSizeMake(100, 100)], @"Should throw if subnodes where modified in layoutSpecThatFits:");
}
#endif
@end