Skip to content

Instantly share code, notes, and snippets.

@stalniy
Created June 25, 2018 18:20
Show Gist options
  • Save stalniy/1c5105638baf477cee2f4d804b28f106 to your computer and use it in GitHub Desktop.
Save stalniy/1c5105638baf477cee2f4d804b28f106 to your computer and use it in GitHub Desktop.
Lazy variables inside hooks
describe('Article', function() {
def('article', function() {
return new Article({ type: 'news', });
});
before(function() {
article.id = 1; // first instance
});
before(function() {
console.log(article.id); // 1
});
beforeEach(function() {
console.log(article.id); // undefined, new variable
article.id = 2; // second instance
});
it('uses the instance created in "beforeEach" block', function() {
expect(article.id).to.equal(2); // true
});
afterEach(function() {
console.log(article.id); // 2, same instance
});
after(function() {
console.log(article.id); // undefined, new instance
article.id = 3;
});
after(function() {
console.log(article.id); // 3, instance from `after` callback
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment