Skip to content
reergymerej edited this page Sep 6, 2014 · 2 revisions

addTest

add your own test to Willy

Add custom tests by passing a named function to willy.addTest.

  • Return the result of this.if so Willy can automatically handle not and eventually for you. if takes 3 arguments:
    • a function passed the value being tested
    • a string explaining what you were testing
    • the value tested (optional)
var willy = require('willy'),
    will = willy.will;

willy.addTest(function beLongerThan(expectedValue) {
    return this.if(

        // a function passed the value being tested
        function (actualValue) {

            // return the result of your test
            return actualValue.length > expectedValue.length;
        },

        // a string explaining what you were testing
        'be longer than',

        // the value tested (optional)
        expectedValue
    );
});

// passes
will('12345').beLongerThan('123');

// fails
will('12345').beLongerThan('12345'); // 'expected <12345> to be longer than <12345>'
will('12345').not.beLongerThan('1234'); // 'expected <12345> not to be longer than <1234>'

// fails as a promise
describe('some test suite', function () {
    it('should be longer than expected', function () {
        var promise = Q.fcall(function () { return '123'; });
        return will(promise).eventually.beLongerThan('12345');
    });
});
Clone this wiki locally