CSS unit testing. Lightning-fast. tape-style.
Last updated 5 years ago by tomekwi .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install tape-css 
SYNC missed versions from official npm registry.

[![Coveralls – test coverage ](https://img.shields.io/coveralls/studio-b12/tape-css.svg?style=flat-square )](https://coveralls.io/r/studio-b12/tape-css ) [![Travis – build status ](https://img.shields.io/travis/studio-b12/tape-css.svg?style=flat-square )](https://travis-ci.org/studio-b12/tape-css ) [![David – status of dependencies ](https://img.shields.io/david/studio-b12/tape-css.svg?style=flat-square )](https://david-dm.org/studio-b12/tape-css ) [![Stability: beta ](https://img.shields.io/badge/stability-beta-green.svg?style=flat-square )](https://github.com/studio-b12/tape-css/milestones/1.0 ) [![Code style: airbnb ](https://img.shields.io/badge/code%20style-airbnb-777777.svg?style=flat-square )](https://github.com/airbnb/javascript )


CSS unit testing. Lightning-fast. tape-style.

Isolates DOM and styles for reproducible unit tests. As elegant and lightweight as tape itself.


That’s how budo + tap-dev-tool + tape-css play together. Other great options: hihat, testron.
Looks slow?


$ npm install tape-css



Pick your favorite flavor of tape – be it tape itself, tape-catch, blue-tape or whatever.

const tape = require('tape');
const test = require('tape-css')(tape);  // We don’t change `tape` in any way.

Pass the DOM tree and styles you want to test. We’ll add it to the <body>* before your test begins – and clean them up right after it has ended.

test('Roses are red, <span>s are blue', {
  dom: document.createElement('span'),
  styles: '* { color: red; } span { color: blue; }',
}, (t) => {
  // Our span and styles are here to play with.
    'rgb(0, 0, 255)'

  // We’ve now cleaned up the place!

tape-css is made to play well with other tools. hyperscript and computed-style can make your tests nicer to read and write:

const h = require('hyperscript');
const style = require('computed-style');
const personOne = h('.person');
const personTwo = h('.person');

test('Everyone has some space to breathe', {
  dom: h('div', [personOne, personTwo]),
  styles: '.person { margin-bottom: 10px } * { padding: 5px }',
}, (is) => {
    personTwo.getBoundingClientRect().bottom -
    '10 px between people'

    style(personOne, 'padding-right'),
    'one has room to move his arm'


Whenever you want to see how your layout actually looks like, use test.only. We’ll only execute this one test and we won’t reset the DOM and styles afterwards. That’s pretty useful while debugging.

test('All is well', /* … */);
test.only('Need to debug this', /* … */);
test('Works alright', /* … */);


Does 928 ms for 21 tests look slow to you? We thought so as well – so we wanted to check why. We created 400 specs with 1000 assertions to check that. Every spec had its own DOM tree and style element created, injected and cleaned up (4 operations per spec). We run and timed that a couple of times in the very same Chrome you’re seeing in the screencast.

Running it took 3 seconds ±200 ms. That’s over 330 tests and 500 DOM operations per second!

tape-css just feels lightening-fast.

It turns out much of the measured time is just the browser rendering the initial page. We tried to time how much that takes – we got wildly differing results though. Feel free to submit a PR if you manage to work this out.


```js test(tape) => ( name? : String, options?: { // All original `tape` options, and: dom? : Element | DocumentFragment styles? : String document? : Document }, callback : Function ) => void ```

If you use tape, you’ll feel right at home. Give us an instance of tape. We won’t change its existing API in any way. We just add a couple of options:

  • dom – one or more DOM elements. We’ll add it to the <body> before your test and clean it up after your test has ended. Default: nothing.

  • styles – a string of CSS. We’ll add it as a <style> to the <head> before your test – and clean it up after your test has ended. Default: nothing.

  • document – a custom implementation of document. It may be useful for testing outside a browser. Default: window.document.


This module was inspired by quixote. Thumbs up for the great idea @jamesshore!

It turned out that quixote wasn’t easy to use with tape though. As well as that, it comes with heavy abstractions (over 3K lines of code) and its own assertion engine – while everything you need for assertions comes with tape already.

We were after something simple which does one thing (<50 LOC last time we checked). And plays well with other simple tools.


MIT © Studio B12 GmbH

Current Tags

  • 1.0.2-beta                                ...           latest (5 years ago)

8 Versions

  • 1.0.2-beta                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.1-beta                                ...           5 years ago
  • 1.0.0-beta                                ...           5 years ago
  • 1.0.0-alpha.2                                ...           5 years ago
  • 1.0.0-alpha.1                                ...           5 years ago
  • 1.0.0-alpha                                ...           5 years ago
  • 0.0.0-work-in-progress                                ...           5 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 8
Dependencies (5)
Dev Dependencies (27)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |