I'm reading the book Testing Angular Applications, which suggests to reset variables to null in the afterEach calls. The accompanying text says:
You can use the teardown part of the test to make sure instances of variables get destroyed, which helps you avoid memory leaks. In this case, you'll use the
afterEachfunction to set thecontactvariable tonull.
Isn't the the used memory freed when the next beforeEach sets a new value or at the end of the whole suite when the describe call is finished? What's the advantage if any of this explicit teardown?
import ContactClass from './contact';
describe('Contact class tests', () => {
let contact: ContactClass = null;
beforeEach(() => {
contact = new ContactClass();
});
it('should have a valid constructor', () => {
expect(contact).not.toBeNull();
});
afterEach(() => {
contact = null;
});
});
I don't such a teardown in Angular's testing guide either: https://angular.io/guide/testing-services