samedi 6 février 2016

Best way to reuse code at unit testing in javascript

I'm using buster.js as the test runner. The basic test is something like:

// Test globals
var var1='foo1', var2='foo2';

// Test run
describe('Description', function(){
    beforeEach(){
        console.log('var2');
    }
    it('should ....', function(){
        expect(var1).toEqual('foo1');
    }
});

Now, imagine I have another test that needs to use the same beforeEach, plus anything else, and the same it, plus anything else.

What would be the best approach to reuse this code in JavaScript? specially in buster.js or mocha?.

Aucun commentaire:

Enregistrer un commentaire