7

The thing is that I have some preparations to do before starting tests. I've got several test files and each of them requires rabbit connection to be opened before each test file, and close it after the ending of all tests in every file. The thing is that I've got to duplicate code in test files to open and close connection. How can deal with connection in one file. I am using TypeScript so several solutions as jest-environment-node, jest-set are not helpful in this case. Also there is a chance that I can solve this proble using setup files as:

"setupFiles": [
      "./src/inttests/partial/mocks/setup.ts"
    ],

And write in setup file something like:

let channel: PubChannel;

beforeAll(() => {
  channel = new PubChannel('amqp://localhost', true);
  exports.ss = new SystemService(channel); // or using globals but it doesn't actually work in both cases.
});

afterAll(async () => {
    await channel.closeConnection();
  }
);

The thing is that I need ss variable to use in tests in order to call some functions. But I don't know how to make them available from setupt.ts file as I can't use export kew word because the value has been modified inside beforeAll scope. Is there any chance to solve this ridiculous problem?

Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297
Vlad Gudikov
  • 103
  • 1
  • 7
  • Have you checked out this similar question yet https://stackoverflow.com/questions/40449434/mocking-globals-in-jest – SteveB Mar 06 '18 at 15:19

0 Answers0