我有一个测试,我想加载一个 UICollectionViewCell ( CustomCollectionViewCell
),将一些数据传递给它,并检查单元格的标签是否用这些数据更新。
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