gpt4 book ai didi

ios - 验证是否在 subview 上设置了正确的框架

转载 作者:行者123 更新时间:2023-11-29 12:25:11 27 4
gpt4 key购买 nike

简介

我想测试是否在 View subview 上设置了正确的框架(作为模拟注入(inject))。

但是我似乎无法找到一种方法来验证是否设置了正确的 CGRect

当前尝试

-(void)testThatCorrectFrameIsSet {
//Arrange
MKTArgumentCaptor *argumentCaptor = [[MKTargumentCaptor alloc] init];
self.sut.subView = mock([UIView class]);

//Act
[self.sut awakeFromNib];

//Assert
[[[MKTVerify(self.sut.subView) withMatcher:[argumentCaptor capture]] setFrame:CGSizeZero];

expect([argumentCaptor.value CGRectValue].size.x).to.beCloseToWithin(42, 0.001);
}

出了什么问题

我得到:

"NSInvalidArgumentException", "-[_NSInlineData CGRectValue]: unrecognized selector sent to instance 0x7af325c0"

这让我想知道如何正确捕获 CGRect 值

旁注

我知道我可以注入(inject)实际的 UIView 而不是模拟的 UIView,但是我正在测试的实际代码阻止我这样做,原因会使这个问题比需要的更难。

最佳答案

我认为您应该使用“CGRectZero”而不是“CGSizeZero”,但这并不能解决问题。

看起来 captor 值不是 NSValue。

//Arrange
MKTArgumentCaptor *argumentCaptor = [[MKTArgumentCaptor alloc] init];
UIView* subView = mock([UIView class]);

// Act
[subView setFrame:CGRectMake(1, 2, 3, 4)];

//Assert
[[MKTVerify(subView) withMatcher:[argumentCaptor capture]] setFrame:CGRectZero];

NSValue* capturedValue = [argumentCaptor value];
if (![capturedValue isKindOfClass:[NSValue class]])
{
NSLog(@"Captured value is no NSValue!");
}

希望这有助于追踪问题。

关于ios - 验证是否在 subview 上设置了正确的框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29345843/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com