Skip to content
This repository has been archived by the owner on Mar 20, 2019. It is now read-only.

Latest commit

 

History

History
70 lines (49 loc) · 1.1 KB

no-describe-variables.md

File metadata and controls

70 lines (49 loc) · 1.1 KB

Disallow variables in describe blocks (no-describe-variables)

Using variables in describe blocks in jasmine can cause memory leaks, e.g.:

describe('Memory leak', function() {

  var a;

  beforeEach(function() {
    a = new Array(10000000).join('a');
  });

  it('test', function() {
    expect(a).toBeDefined();
  });
});

Due to internal design of the library such variables can not be collected by the garbage collector. Instead the suggested pattern to use is:

describe('Memory leak', function() {

  beforeEach(function() {
    this.a = new Array(10000000).join('a');
  });

  it('test', function() {
    expect(this.a).toBeDefined();
  });
});

Rule details

The following are considered warnings:

describe('Foo', function() {
  
  var foo;

  beforeEach(function () {
    foo = new Foo();
  });

  it('works', function () {
    expect(foo).toBeDefined();
  });

});

The following patterns are not warnings:

describe('Bar', function() {

  beforeEach(function () {
    this.bar = new Bar();
  });

  it('works', function () {
    expect(this.bar).toBeDefined();
  });

});