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

241 views Asked by At

I recently upgraded my project to use Nimble 9.0.0. Around the same time I had to make one my collections a dictionary of type [AnyHashable : AnyHashable]. I have code that runs when that collection is modified and sends what was added in a notification as part of the userInfo dictionary.

Here's how I'm verifying the notification: expect { try? cache.add(items: itemsToAdd)}.to(postNotifications(equal([itemAddedExpectedNotification])))

This started failing even though the values are the same as it seems to expect the user info dictionary to maintain order when dictionaries aren't really ordered. Is there a way for me to explicitly test the userInfo portion?

Here's the error message from 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"))]]])]>
1

There are 1 answers

0
Ahmad On BEST ANSWER

I was able to use this - Quick/Nimble notification userInfo testing to write a custom matches and added my own variation to match multiple notifications.