如何使用 Nimble 测试通知的 userInfo 部分?

How do I test the userInfo portion of a notification with Nimble?

我最近升级了我的项目以使用 Nimble 9.0.0。大约在同一时间,我不得不让我的 collections 成为 [AnyHashable : AnyHashable] 类型的字典。我有代码在修改 collection 时运行,并发送通知中添加的内容作为 userInfo 字典的一部分。

以下是我验证通知的方式: expect { try? cache.add(items: itemsToAdd)}.to(postNotifications(equal([itemAddedExpectedNotification])))

这开始失败,即使这些值与它似乎期望用户信息字典在字典没有真正排序时保持顺序相同。有没有办法明确测试 userInfo 部分?

这是来自 Xcode 12 的错误消息:

Address and Undefined Behavior Sanitizers: expected to equal 
<[name = itemAdded, object = Optional(Cache count : 0, cache limit: -1), userInfo = Optional([AnyHashable("items"): [["key": Optional(AnyHashable("CachedItem-2")), "value": Optional(AnyHashable(2))], ["key": Optional(AnyHashable("CachedItem-3")), "value": Optional(AnyHashable(3))], ["value": Optional(AnyHashable(1)), "key": Optional(AnyHashable("CachedItem-1"))], ["key": Optional(AnyHashable("CachedItem-0")), "value": Optional(AnyHashable(0))]]])]>, got
 <[name = itemAdded, object = Optional(Cache count : 4, cache limit: -1), userInfo = Optional([AnyHashable("items"): [["key": Optional(AnyHashable("CachedItem-3")), "value": Optional(AnyHashable(3))], ["value": Optional(AnyHashable(1)), "key": Optional(AnyHashable("CachedItem-1"))], ["value": Optional(AnyHashable(0)), "key": Optional(AnyHashable("CachedItem-0"))], ["value": Optional(AnyHashable(2)), "key": Optional(AnyHashable("CachedItem-2"))]]])]>

我能够使用它 - Quick/Nimble notification userInfo testing 编写自定义匹配并添加我自己的变体以匹配多个通知。