Skip to content

Instantly share code, notes, and snippets.

@zcmgyu
Forked from icirellik/test.js
Created August 22, 2019 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zcmgyu/d21f6e5fbba0a2e1e6b0750fb97fdcdb to your computer and use it in GitHub Desktop.
Save zcmgyu/d21f6e5fbba0a2e1e6b0750fb97fdcdb to your computer and use it in GitHub Desktop.
Pass data between beforeEach, afterEach and it in mocha tests.
var expect = require('expect');
describe.only('Sample', function () {
beforeEach(function () {
this.currentTest.value = 'Winning!';
});
it('Uses current test data', function () {
expect(this.test.value).to.equal('Winning!');
this.test.value = 'Win Later';
});
afterEach(function () {
expect(this.currentTest.value).to.equal('Win Later');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment