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

Test context should be shared by before and after #36

Open
polotek opened this issue Aug 24, 2012 · 1 comment
Open

Test context should be shared by before and after #36

polotek opened this issue Aug 24, 2012 · 1 comment

Comments

@polotek
Copy link
Contributor

polotek commented Aug 24, 2012

Right now it looks like each test gets a unique context (e.g. this). But the context should be shared by the before() and after() methods. This enables you to set up test-specific state and clean it up without polluting each actual test or polluting the closure scope. See example.

describe('testing the context', function() {
  before(function() {
    this.foo = 'unit';
  });

  after(function() {
    this.foo = null;
  });

  it('should have the context set', function() {
    expect(this.foo).to(be, 'unit');
  });
});

The test context should probably be cleared out after each test too. e.g. all properties set to null.

@polotek
Copy link
Contributor Author

polotek commented Aug 24, 2012

Courtesy of me and @uzikilon :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant