0.0.6 • Published 8 years ago

expect.underscore.js v0.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Expect.underscore

Expectjs with underscore support.

expect([1,2,3,4]).to._.find(function(n) { 
    return n % 2 == 0;
});

expectjs is a 'Minimalistic BDD assertion toolkit', which is very simple to use, but is short in matchers that makes writing tests less jolly.

This extension inserts underscore functions as matchers under the belt, so you can easily test with power of underscore in your hands.

How to use

Node

$ npm install expect.underscore.js

Example

var expect  = require('expect.js'),
    _       = require('underscore');

// PATCH expect here
expect = require('expect.underscore.js').extend(expect, _);

describe('check users for fred', function() {
    var userNames = [
        'barney',  
        'fred',
        'pebbles',
    ];
    var users = [
      { 'user': 'barney',  'active': true },
      { 'user': 'fred',    'active': false },
      { 'user': 'pebbles', 'active': false }
    ];

    it('using expectjs', function() {
        // you either check with the whole object,
        expect(userNames).to.contain('fred');

        // or split the lines
        var fred = _.find(users, {user: 'fred'});
        expect(fred).to.be.ok();
    });

    it('using _.find', function() {
        // better readability
        expect(users).to._.find({user: 'fred'});
    });


    describe('.not.to', function() {
        it('using _.find', function() {
            expect(users).not.to._.find({
                active: undefined
            });
        });
    });
});

You can use every underscore methods under the .to._ object, and it will check if the result is .ok().

API

To check the full methods supported, check the underscore document.

If you prefer lodash, you can pass lodash as an argument instead.

TODO

Currently tested with lodash (sorry), and only in NodeJS.

0.0.6

8 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago