Skip to main content
Version: 4.x.x

Testing Isolation

Isolation is extremely important for making both deterministic and valid tests. Due to the approach to architecture where the client is a global module, we need to bring some of our attention to it.


Clear

The client.clear() request allows us to isolate our test cases within one file. It will reinitialize the subsystems of our client.


Node cache cleanup

To properly isolate our tests, we need to be sure that the node instance require.cache will be reset. This way our global client module will be restarted and we will have the environment prepared.

Jest

beforeEach(() => {
// We need to reset modules cache as client is globally exported module
// This way it will not get mixed-up with other test cases running in parallel
jest.resetModules();
// Clean the environment to make sure it's isolated
client.clear();
});