Ocha

Ocha is a Chai-style assertion library for Sass.

@function squared($n) {
  @return $n * $n
}

@include expect(square(2) to equal 4);

Overview

Inspired by Chai, Ocha allows you to write expressive assertions for your Sass unit tests using a simple, fluid syntax. Nearly every function available in Chai is also in Ocha, from equality checks to inspection.

Ocha hooks directly into True, a Sass test runner designed to integrate into popular test frameworks like Mocha and Jasmine. This means you can easily test your code in automated environments such as Travis.

Installation

Ocha is on npm and Bower.

npm install ocha
bower install ocha

Usage

Use Ocha’s expect() mixin with True’s test-module() and test() mixins to write assertions. Learn more about setting up True.

@include test-module('Number Functions') {
  @include test('square [function]') {
    @include expect(square(2) to equal 4);
  }
}
View Full API → 26 assertion functions!

Contribute

Ocha is open source and hosted on GitHub. Feel free to open an issue with any bugs you run into, or submit a pull request to contribute to the codebase yourself.

Etymology

Japanese Kanji for tea.

The Japanese word for tea, ocha (pronounced "oh-chya"), comes from one Chinese pronunciation of the word, chá. And indeed, the Persian word chai is dervied from this as well.

The Kanji used is also dervied from the Chinese character. It's comprised of three radicals: a person (人) harvests leaves (艹) from a plant (木). The symbol 朩 is used in place of 木.

Colophon

Ocha was created by Geoff Kimball, a front-end developer and designer. Other Sass-ey things I've worked on include Foundation, Motion UI, and Responsive Modular Scale. And yes, I did just switch from third- to first-person mid-paragraph.