Skip to content

context should not exist on before/after tests. #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jamestalmage
Copy link
Contributor

IMO, since context is not shared in before and after hooks.
It should be an error to access it in either scenario.

(cherry picked from commit f298d72 on #243)

@jamestalmage
Copy link
Contributor Author

This becomes easier to solve with a helpful Error message with the attached metadata from #243 .

function checkContextAccess(test) {
    if (test.metadata.type === 'before' || test.metadata.type === 'after') {
      throw new Error('test.context access is not allowed in before/after hooks');
    }
}

Object.define(Test.prototype, 'context', {
  get: function () {
    checkContextAccess(this);
    return this._context;
  }, 
  set: function (newContext) {
    checkContextAccess(this);
    this._context = context;
  }
});

sindresorhus added a commit that referenced this pull request Nov 23, 2015
…ter-hooks

context should not exist on before/after tests.
@sindresorhus sindresorhus merged commit 293acf2 into avajs:master Nov 23, 2015
@jamestalmage jamestalmage deleted the remove-context-on-before-after-hooks branch November 23, 2015 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants