Created
June 25, 2018 18:20
-
-
Save stalniy/1c5105638baf477cee2f4d804b28f106 to your computer and use it in GitHub Desktop.
Lazy variables inside hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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