vendredi 27 mai 2016

Get a list of mocha `describe` calls for a given test

Is there a way to get an array of messages passed to describe?

I would like to dynamically create the testList array from the values passed as messages in the describe calls below.

Example Test

<script src="http://ift.tt/1qL1eRu"></script>
<script src="http://ift.tt/25rvl2E"></script>
<link href="http://ift.tt/1qQzn1G" rel="stylesheet"/>
<div id="mocha"></div>
<script>
    mocha.setup('bdd');
</script>
<script>
    mocha.checkLeaks();
    //mocha.globals(['jQuery']);
</script>
<script>
    var expect = chai.expect;
    var testList = ['methodTrue', 'methodFalse', 'methodIdentity'];
    var testObject = {
        methodTrue: function () {return true;},
        methodFalse: function () {return false;},
        methodIdentity: function (n) {return n;}
    }
    describe('testObject', function () {
        describe('methodTrue', function () {
            it('should be a method', function () {
                expect(testObject.methodTrue).to.be.a('function');
            });
        });
        describe('methodFalse', function () {
            it('should be a method', function () {
                expect(testObject.methodFalse).to.be.a('function');
            });
        });
        describe('methodIdentity', function () {
            it('should be a method', function () {
                expect(testObject.methodIdentity).to.be.a('function');
            });
        });
        it('should have a method for every test', function () {
            Object.keys(testObject).forEach(function (v, i) {
                expect(testList.indexOf(v), 'no test for ' + v).to.be.above(-1);  
            });
        });
    });
    mocha.run();
</script>

Aucun commentaire:

Enregistrer un commentaire