Miss any of our Open RFC calls?Watch the recordings here! »

mingus

0.12.0 • Public • Published

mingus

mingus is a testing library for React components using babel, mocha, istanbul, sinon, and chai.

Install

To install the latest release:

npm install mingus

To build the latest code directly from source:

npm install git://github.com/jmcriffey/mingus.git

Usage

src/CoolComponent.js:

import React from 'react';
import someLib from 'someLib';
 
 
class CoolComponent extends React.Component {
    render() {
        return (
            <ul className="cool-list">
                <li className="cool-list-item">1</li>
                <li className="cool-list-item">2</li>
            </ul>
        );
    }
 
    getNum() {
        return someLib.getNum();
    }
}
 
export default CoolComponent;

tests/CoolComponent-test.js:

import Mingus from 'mingus';
import someLib from 'someLib';
 
import CoolComponent from './CoolComponent';
 
 
Mingus.createTestCase({
    beforeEach() {
        this.rendered = this.renderComponent(CoolComponent);
        this.component = this.createComponent(CoolComponent);
    },
 
    testType() {
        this.assertIsType(this.rendered, 'ul')
    },
 
    testClass() {
        this.assertHasClass(this.rendered, 'cool-list');
    },
 
    testChildrenClasses() {
        this.assertEveryChildHasClass(this.rendered, 'cool-list-item');
        this.assertSomeChildHasClass(this.rendered, 'cool-list-item');
    },
 
    testChildrenTypes() {
        this.assertEveryChildIsType(this.rendered, 'li');
        this.assertSomeChildIsType(this.rendered, 'li');
    },
 
    testNthChildClass() {
        this.assertNthChildHasClass(this.rendered, 0, 'cool-list-item');
    },
 
    testNthChildType() {
        this.assertNthChildIsType(this.rendered, 0, 'li');
    },
 
    testGetNum() {
        this.stub(someLib, 'getNum', () => 777);
        this.assertEqual(component.getNum(), 777);
    }
});

On the command line:

mingus cover && mingus check-coverage

Without coverage:

mingus unit

License

MIT License

Install

npm i mingus

DownloadsWeekly Downloads

8

Version

0.12.0

License

MIT

Last publish

Collaborators

  • avatar