MagicalRecord termination block not called in test target

MagicalRecord.saveWithBlock({ context in

        if let items = dictionary["items"] as? Array<NSDictionary> {
            for itemInfo in items {
                DBItem.findOrUpdateItemWithDictionary(itemInfo, inContext: context)
            }
        }
        //is called
        if let sets = dictionary["item_sets"] as? Array<NSDictionary> {
            for setInfo in sets {
                DBSet.findOrUpdateSetWithDictionary(setInfo, inContext: context)
            }
        }

        }, completion: { finished, error in

        completionBlock(error) //is not called
})

This is how I set up my main data stack:

MagicalRecord.setupCoreDataStackWithInMemoryStore()
+2
source share
1 answer

The method saveWithBlock:runs asynchronously. The test can be completed before the completion block is called, although I do not know how your test code is.

https://github.com/magicalpanda/MagicalRecord/blob/c7b14f658b4fca32f8d33f8f76160203053ce4b9/MagicalRecord/Core/MagicalRecord%2BActions.m#L14-L35

Could you try changing the method saveWithBlock:to saveWithBlockAndWait:? It runs synchronously. Or wait to make an asynchronous call with XCTestExpectation?

+1
source

Source: https://habr.com/ru/post/1538896/


All Articles