Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Nimble Matchers for UIKit
This package provides a number of nimble matchers intended for verifying the state of UIKit components.
I strongly believe that unit tests should be written in a declarative manner, and while
expect(label?.text).to(equal("some value")) works and is somewhat descriptive, it's not really declarative. I find
expect(label).to(displayText("some value")) better conveys the intent behind the behavior being described.
Though, the real impetus that started me on this path of writing matchers is the
beVisible matcher. The main ways to set a view as invisible are 1. set
isHidden to true and 2. Remove it from the view hierarchy. When you're unit testing, you need to assert on the view that's actually hidden or removed (say, a container view), and you also have the test specifying the method used to make the view hidden from the user.
beVisible combines both of those by verifying that an asserted-on
UIView is within (or not) a given
UIView hierarchy. There are also other ways of making a view invisible (which usually are the result of bugs) which this matcher attempts to check for.
Currently, this provides the following matchers:
beAnAccessibilityElementverifies whether the
NSObjectbeing asserted on has
haveAccessibilityLabelverifies the contents of the
haveAccessibilityTraitsverifies the contents of the
haveAccessibilityValueverifies the contents of the
haveAccessibilityHintverifies the contents of the
beEnabledverifies the contents of the
isEnabledproperty. This is done with an
Enablableproperty that all three of those objects conform to.
beVisibleverifies whether a given
UIViewis visible inside of another
UIViewhierarchy - or is shown within a
UIViewController. Being "visible" means that the asserted-on view is within the expected view hierarchy, and that none of the views involved have:
isHiddenset to true,
alphaset to 0,
frame.size.widthset to 0, or
frame.size.heightset to 0. It does not check to see if the view is occluded by other views, nor other ways of hiding a view from the user.
displayTextverifiers whether a given
UITextView) set to the expected string value (using the
TextDisplayercustom protocol) that
UITextViewconform to, or the
title(for:)method returns the expected string value for the given
displayPlaceholderverifies that the contents of the
placeholderproperty matches the given string value.
haveImageverifies that the
UIButtonare displaying the given
UIImage. This works on a pointer-level comparison, and nothing particularly "smart".
haveKeyCommandverifies that the
keyCommandsproperty contains a
UIKeyCommandmatching the given properties.
haveTextColorverifies that the
UITextView) set to the expected color (using the
TextDisplayercustom protocol), or the
titleColor(for:)method returns the expected color for the given
haveTheDefaultPointerInteractionverifies that you did the bare minimum to give the
UIButtonthe "default" pointer interaction. What this means for
interactionsproperty contains 1 and only 1
UIPointerInteractioninstance, and that
UIPointerInteractiondoesn't have a delegate. For
UIButton, it means that you did not add any
UIPointerInteractions, and instead you set the
isPointerInteractionEnabledto true, and set
beOnverifies that the
isOnproperty is set to
beOffverifies that the
isOnproperty is set to