I have a test where I want to load a UICollectionViewCell (CustomCollectionViewCell
), pass some data to it and check if the labels of the cell are updated with this data.
cell.nameLabel
is a UILabel of the cell and the method setText
is called but the text itself is never updated.
cell.nameLabel.text
returns always the initial text defined in the xib.
The label is defined as follows:
@property (nonatomic, weak) IBOutlet UILabel *nameLabel;
And the spec:
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