In the original code, the restoration of the original _mounting block occurs after the __detox_sync_waitAndMountWithTimeout:timeout method call. This leads to the original _mounting block being restored after it has potentially been altered by the __detox_sync_waitAndMountWithTimeout:timeout method, which is not the desired behavior.
The fix involves moving the restoration of the original _mounting block inside the swizzled block (swizzledMountingBlock). Now, whenever the swizzled block is executed, the original _mounting block is restored first, ensuring the original behavior is retained before any other operations within the swizzled block are performed.
In the original code, the restoration of the original
_mounting
block occurs after the__detox_sync_waitAndMountWithTimeout:timeout
method call. This leads to the original_mounting
block being restored after it has potentially been altered by the__detox_sync_waitAndMountWithTimeout:timeout
method, which is not the desired behavior.The fix involves moving the restoration of the original
_mounting
block inside the swizzled block (swizzledMountingBlock
). Now, whenever the swizzled block is executed, the original_mounting
block is restored first, ensuring the original behavior is retained before any other operations within the swizzled block are performed.This issue was reported here: https://github.com/wix/Detox/issues/4253 and was reproduced thanks to @ldalzottomp.