Skip to content

Commit

Permalink
Improve UIView Auto Layout tests (#337)
Browse files Browse the repository at this point in the history
* Improve `UIView` Auto Layout tests

* Add local variable to DRY implementation

* Add non-zero dimensions

* Use consistent formatting
  • Loading branch information
tinder-cfuller authored Feb 13, 2024
1 parent 9d33ee2 commit 5ef2f1f
Show file tree
Hide file tree
Showing 2 changed files with 426 additions and 173 deletions.
10 changes: 7 additions & 3 deletions Tests/LayoutTests/Support/NimbleMatchers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ extension XCTestCase {
// swiftlint:disable cyclomatic_complexity

@MainActor
internal func match(_ expectedConstraint: NSLayoutConstraint) -> Matcher<NSLayoutConstraint> {
internal func match(
_ expectedConstraint: NSLayoutConstraint,
isActive: Bool? = nil // swiftlint:disable:this discouraged_optional_boolean
) -> Matcher<NSLayoutConstraint> {
// swiftlint:disable:next closure_body_length
Matcher { expression in
guard let constraint: NSLayoutConstraint = try expression.evaluate()
else { return MatcherResult(status: .fail, message: .expectedTo("not be nil, got <nil>")) }
guard constraint.isActive == expectedConstraint.isActive
let isActiveExpected: Bool = isActive ?? expectedConstraint.isActive
guard constraint.isActive == isActiveExpected
else {
let message: String = """
match `isActive` <\(expectedConstraint.isActive)>, \
match `isActive` <\(isActiveExpected)>, \
got <\(constraint.isActive)>
"""
return MatcherResult(status: .fail, message: .expectedTo(message))
Expand Down
Loading

0 comments on commit 5ef2f1f

Please sign in to comment.