mardi 16 juin 2020

Synchronous mocha.js before and after hooks are not running

I set up simple mocha.js test in order to do some experiments. No matter what I do, I cannot make before and after functions execute. My code is following:

My code (/test/tests.js):

const expect = require('chai');
const assert = require('assert');


describe('Number comparison', function(){
    before(function(){
        console.log('====before====');
    });

    after(function(){
        console.log('====after====');
    });

    beforeEach(function() {
        console.log('===beforeEach===');
    });

    afterEach(function(){
        console.log('====afterEach====');
    });

    it('Compare simple assertion', function () {
        assert.equal(1, 1);
    });
});

After running tests, output is always as below. You can notice missing before and after debug statements.

  Number comparison
===beforeEach===
    ✓ Compare simple assertion
====afterEach====

  1 passing (3ms)

It looks like my code should work... Take a look on example mentioned on BDD Interface part on this site (BBD is default interface for mocha.js), where it is used in very similar manner:

http://ricostacruz.com/mocha/

Note:

I am aware of Mocha before and after hooks not executing, but as you can notice this is Synchronous test unlike mentioned question.

Aucun commentaire:

Enregistrer un commentaire