Span
instances represent an imaginary line between two X or Y coordinates. They can be horizontal or vertical, but not diagonal. They are created by PositionDescriptor.to()
.
If either end of the span is not rendered, the whole span is considered to be not rendered.
Use these methods to make assertions about the size of the span. In all cases, if the assertion is true, nothing happens. Otherwise, the assertion throws an exception explaining why it failed.
Span sizes are always positive.
Stability: 3 - Stable
Check whether the length of a span matches a size.
span.should.equal(expectation, message)
Assert that the span length matches the expectation.span.should.notEqual(expectation, message)
Assert that the span length does not match the expectation.
Parameters:
-
expectation (SizeDescriptor equivalent)
The size to compare against. -
message (optional string)
A message to include when the assertion fails.
Example:
// "The whitespace between the columns should be 20 pixels wide."
leftColumn.right.to(rightColumn.left).should.equal(20);
Stability: 3 - Stable
Check whether the length of the span is bigger or smaller than a size.
size.should.beBiggerThan(expectation, message)
Assert that the span is bigger than the expectation.size.should.beSmallerThan(expectation, message)
Assert that the span is smaller than the expectation.
Parameters:
-
expectation (PositionDescriptor equivalent)
The size to compare against. Must be be rendered. -
message (optional string)
A message to include when the assertion fails.
Example:
// "The testimonials should be shorter than the viewport."
firstTestimonial.top.to(lastTestimonial.bottom).should.beSmallerThan(frame.viewport().height);
Use these properties to make additional assertions about the span.
Stability: 3 - Stable
span.center (
PositionDescriptor
)
The horizontal center of the span. For use with horizontal spans only.span.middle (
PositionDescriptor
)
The vertical middle of the span. For use with vertical spans only.
Example:
// "The thumbnail should be centered to the left of the description."
thumbnailImage.center.should.equal(thumbnailComponent.left.to(description.left));
These methods are useful when you want to compare spans that aren't exactly the same.
Stability: 3 - Stable
Create a SizeDescriptor
that's bigger than this span.
size = span.plus(amount)
-
size (
SizeDescriptor
)
The size. -
amount (
SizeDescriptor equivalent
)
The number of pixels to increase.
Stability: 3 - Stable
Create a SizeDescriptor
that's smaller than this one.
size = span.minus(amount)
-
size (
SizeDescriptor
)
The size. -
amount (
SizeDescriptor equivalent
)
The number of pixels to decrease.
Stability: 3 - Stable
Create a SizeDescriptor
that's a multiple or fraction of the size of this one.
size = span.times(multiple)
-
size (
SizeDescriptor
)
The size. -
multiple (number)
The number to multiply.