У меня есть тест, где я хочу загрузить 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