Monday, 1 May 2017

Sharing a variable across multiple test files

I want to share a variable with the multiple test files.

Here is the file that inits the connection object socket

let socket;

describe('Starting the test suite', function () {
    let connected = false;
    let connectionParams = {
        hostname: 'localhost',
        port: '8000'
    };

    before(function () {
        /**
         * Establish a connection before tests are
         * executed
         */
        socket = socketCluster.connect(connectionParams);
    });

    it('Check if the connection has been made', function(done) {
        this.timeout(1000); // timeout with an error, if done is not called within 1000 milliseconds
        socket.on('connect', function () {
            assert.ok(true);
            done();
        });
    });
});

I need to share the variable named socket that is initialized in the before block.

How could I do this?



via Suhail Gupta

No comments:

Post a Comment