Ocha
A BDD-style assertion library for Sass. Eventually it will maybe work with True.
Installation
It's not on npm yet!
Usage
Use the expect()
mixin to write an assertion. Pass a value to check, and then a series of language functions. Most assertions also require a final value to compare with.
; ;
API
Language Chains
These functions don't do anything—they just make your assertion more readable.
to
be
been
is
which
and
has
have
with
at
of
same
Negation
Throw the word not
in an assertion to check for the opposite result.
Note that, since not
is a special keyword in Sass, you have to put it in quotes.
Comparison
equal($value)
Check if a value equals $value
.
above($floor)
Check if a value is greater than $floor
.
least($floor)
Check if a value is greater than or equal to $floor
.
below($floor)
Check if a value is less than $floor
.
most($floor)
Check if a value is less than or equal to $floor
.
within($floor, $ceiling)
Check if a value is within the range of $floor
and $ceiling
(including those values).
Type Comparison
a($type)
Check if a value has the type of $type
.
to be a list);
ok
Check if a value is truthy:
true
- A list or map that isn't empty
- A number greater than 0
true
Check if a value is true
. Note that this function has to be used with quotes around it, because it's a special keyword in Sass.
false
Check if a value is false
. Note that this function has to be used with quotes around it, because it's a special keyword in Sass.
null
Check if a value is null
. Note that this function has to be used with quotes around it, because it's a special keyword in Sass.
Inspection
lengthOf($length)
Check if a list has a length equal to $length
.
;
length
Check if a list has a length that satisfies a certain criteria. Pair it with above
, least
, below
, most
, or within
.
;
empty
Check if a list has a length of 0.
;
string($substring)
Check if a string contains $substring
.
contain($needle)
Check if a string contains $needle
, or check if a list contains $needle
.
to contain 'one');
include($needle)
Check if a string contains $needle
, or check if a list contains $needle
.
to include 'one');
keys($keys)
If you call keys
by itself, check if a map contains every key within $keys
and no other keys.
;
If you call contain keys
, check if a map contains every key within $keys
. If the map has other keys, that's fine.
;
If you call any keys
, check if a map contains any key within $keys
.
;