Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve UIView Auto Layout tests #337

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading