Open Source

True: Sass Unit Testing

Write your tests in Sass, and report with Mocha

True is a full-featured unit-testing library for Sass. The core functionality is written in pure SassScript, so it can be used anywhere Sass is compiled. Advanced features are available with our test-runner integration and Mocha.

For Sass developers, by Sass developers

‘npm package’ ‘build status’

We designed True as one of the first testing frameworks for the Sass language, in order to provide tests for Susy, our Sass layout toolkit. Since then, True has become the only full-featured unit-testing software that allows you to write and compile your tests with plain Sass mixins.

Write your tests in Sass, compile them with Sass, and then (optionally) pass the results to a Javascript test-runner for command-line control and reporting.

Read The Docs

Getting Started

Install the sass-true module using yarn or npm:

yarn add sass-true --dev
npm install sass-true --save-dev

Then import the library, along with the code you are testing in Sass:

@import "<path/to/node_modules>/true/sass/true";

Define tests in Sass with a BDD (describe/it) or TDD (test-module/test) syntax:

@include describe('multiply() function') {
  @include it('Returns the result of multiplication') {
    // …
  }
}

@include test-module('multiply() function') {
  @include test('Returns the result of multiplication') {
    // …
  }
}

Compare internal Sass values (variables and functions) by asserting is-equal, is-unequal, is-true, or is-false:

// Testing Functions
@include assert-equal(
  multiply(12, 2),
  24
);

Test CSS output (mixins) with the assert, output, and expect mixins:

// Testing Mixins
@include assert {
  @include output {
    @include font-size('large');
  }

  @include expect {
    font-size: 2rem;
    line-height: 3rem;
  }
}

Optionally show a summary report in the CSS output and/or the command line:

@include report;

Or use our Javascript integration to run and report tests directly in the command line. Read the docs for more!

Let’s Talk About Your Web Project

Give Wings to Your Vision

OddBird is a full-stack design and development agency, partnering with funded startups and enterprise companies to create custom Django web applications. No matter your size, we’re ready to help take your project from concept to launch. Reach out any time: inquire about our services, set up a free consultation, invite us to speak at your company or event, or just say hello. Miriam Suzanne will get back to you soon.

Get a free consulation