True is a unit-testing tool for Sass code – initially developed for the Susy layout toolkit. All of the test code is written in pure Sass, and can be compiled by any Sass compiler – but we also provide integration with Mocha JS, for extra features and improved reporting.
True the wheels of a bicycle after striking a pothole.
True up the sides of a door.
True your sweet plugin before you deploy.
In command line:
# npm modulenpm install sass-true
Import in your test directory, like any other Sass file:
Depending on your setup, you may need to include the full path name:
// This is only an example;
truewill show detailed information in the terminal for debugging failed assertions, or reporting final results. This is the default, and best for compiling without Mocha.
falsewill turn off all terminal output from Sass, though Mocha will continue to use the terminal for reporting.
True is based on common JS-testing patterns,
allowing both a
and the newer
it for defining the structure:
This is the same as…
Sass is able to compare values internally, meaning function-output and variable values can easily be compared and reported during Sass compilation.
CSS output tests, on the other hand,
have to be compared after compilation is complete.
You can do that by hand if you want
git diff is helpful for noticing changes),
or you can use out Mocha JS integration.
Output tests fit the same structure,
but assertions take a slightly different form,
with an outer
and a matching pair of
to contain the output-values.
// Test CSS output from mixins
You can optionally show a summary report in CSS and/or the command line, after the tests have completed:
true via npm (
npm install sass-true).
Write some Sass tests in
test/test.scss (see above).
Write a shim JS test file in
var path = ;var sassTrue = ;var sassFile = path;sassTrue;
Run Mocha, and see your Sass tests reported in the command line.
You can call
runSass more than once, if you have multiple Sass test files you
want to run separately.
The first argument to
runSass accepts the same options that node-sass'
renderSync function accepts. The only modification
runSass makes is to add
True's sass path to the
includePaths option, so
@import 'true'; works in
your Sass test file.
Any other JS test runner with equivalents to Mocha's
be usable in the same way; just pass your test runner's
If True's Mocha plugin can't parse the CSS output from True, it'll give you
some context lines of CSS as part of the error message. This context will
likely be helpful in understanding the parse failure. By default it provides up
to 10 lines of context; if you need more, you can provide a numeric fourth
runSass, the maximum number of context lines to provide.
Run Mocha using the Grunt task supplied by grunt-mocha-cli
npm install grunt-mocha-cli --save-dev