I've recently been testing a web application developed in Node.js. We're using Mocha, Sinon, Supertest and Proxyquire.
Before I entered the project, another guy developed the test suite for the web application.
In the test folder, there is a Javascript file named commons.js
commons.js
global.sinon = require('sinon');
global.expect = require('chai').expect;
global.supertest = require('supertest');
global.request = supertest('http://localhost:8051');
global.express = require('express');
global.app = express();
global.proxyquire = require('proxyquire');
These variables are used in all the tests. They're used for testing controllers and routers.
I was wondering if this is a good practice to follow. On the one hand, I know that we should avoid using global variables in our applications, but I don't know if this also applies for testing. On the other hand, I feel like repeating those variables at beginning of each test file is somehow repeating the DRY principle
What should I do? Should I refactor all tests or just leave them as they are now?
Aucun commentaire:
Enregistrer un commentaire