0
UICollectionViewCell (CustomCollectionViewCell
)을로드하고 일부 데이터를 전달하고 셀의 레이블이이 데이터로 업데이트되는지 확인해야하는 테스트가 있습니다.단위 테스트에서 UICollectionViewCell 하위 뷰가 업데이트되지 않음
cell.nameLabel
은 셀의 UILabel이며 setText
메서드가 호출되지만 텍스트 자체는 업데이트되지 않습니다.
cell.nameLabel.text
은 항상 xib에 정의 된 초기 텍스트를 반환합니다. 다음과 같이
레이블이 정의됩니다
@property (nonatomic, weak) IBOutlet UILabel *nameLabel;
그리고 사양 :
SPEC_BEGIN(CustomCollectionViewCellSpec)
describe(@"CustomCollectionViewCell", ^{
__block CustomCollectionViewCell *cell = nil;
__block CustomCollectionViewCellData *cellData = nil;
beforeEach(^{
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"CustomCollectionViewCell"
owner:self
options:nil];
for (id object in objects) {
if ([object isKindOfClass:[CustomCollectionViewCell class]]) {
cell = (CustomCollectionViewCell *)object;
break;
}
}
cellData = [[CustomCollectionViewCellData alloc] init];
cellData.name = @"Custom name";
});
afterEach(^{
cell = nil;
cellData = nil;
});
it(@"should populate the views with the cell data", ^{
[[cell.nameLabel should] receive:@selector(setText:)
withArguments:cellData.name];
[cell configureWithCellData:cellData];
[[cell.cellData should] equal:cellData];
[[cell.nameLabel.text should] equal:cellData.name];
});
});
SPEC_END