Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A proof of concept I created in Sept of 2012 showing how unit testing of SCSS code could work. This code was runnable, or close to it, with a runner I wrote, but is not in good enough shape to post.
@import "../base/functions";
$base-size: 10px;
@function to-equal($actual, $expected){
@if $expected == $actual {
@return true;
} @else {
@return $actual;
}
}
@function to-almost-equal($actual, $expected, $variance: .5){
@if $actual - $expected <= $variance {
@return true;
} @else {
@return $actual;
}
}
strip-units {
remove-from-em {
expect: to-equal(strip-units(1em), 1);
}
}
to-px {
basic-conversion {
expect: to-equal(to-px(1em), 10px);
}
}
to-em {
basic-conversion {
expect: to-equal(to-em(10px), 1em);
}
convert-with-em-context {
expect: to-equal(to-em(10px, 2em), .5em);
}
convert-with-em-context-messy {
expect: to-almost-equal(to-em(14px, 3em), .46667em);
}
convert-with-px-context {
expect: to-equal(to-em(10px, 20px), .5em);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment