Skip to content

Instantly share code, notes, and snippets.

@frootloops
Created August 6, 2021 09:06
Show Gist options
  • Save frootloops/96bbf00568966299843399e2b5054756 to your computer and use it in GitHub Desktop.
Save frootloops/96bbf00568966299843399e2b5054756 to your computer and use it in GitHub Desktop.
class AnimatorSpy: Animator {
var invokedAnimate = false
var invokedAnimateCount = 0
var invokedAnimateParameters: (duration: TimeInterval, Void)?
var invokedAnimateParametersList = [(duration: TimeInterval, Void)]()
var shouldInvokeAnimateAnimations = false
var stubbedAnimateCompletionResult: (Bool, Void)?
var stubbedAnimateResult: Bool! = false
func animate(duration: TimeInterval, animations: () -> (), completion: (Bool) -> ()) -> Bool {
invokedAnimate = true
invokedAnimateCount += 1
invokedAnimateParameters = (duration, ())
invokedAnimateParametersList.append((duration, ()))
if shouldInvokeAnimateAnimations {
animations()
}
if let result = stubbedAnimateCompletionResult {
completion(result.0)
}
return stubbedAnimateResult
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment