Last active
March 14, 2016 18:48
-
-
Save lucasconstantino/269e24094898832068f3 to your computer and use it in GitHub Desktop.
Helper method to simulate beforeAll behavior for tests using protractor.
This file contains hidden or 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
/** | |
* @file | |
* Protractor beforeAll implementation as helper. | |
*/ | |
var history = []; | |
/** | |
* BeforeAll implementation. | |
*/ | |
function beforeAll(callback) { | |
(callback.length ? beforeAllAsync : beforeAllSync).call(null, callback); | |
} | |
/** | |
* BeforeAll Synchronous: used when there is no "done" argument | |
* defined in the callback. | |
*/ | |
function beforeAllSync(callback) { | |
// Avoid registering multiple beforeEach callbacks. | |
if (!~history.indexOf(callback)) { | |
beforeEach(function () { | |
// Only execute if never executed before. | |
if (!~history.indexOf(callback)) { | |
history.push(callback); | |
callback(); | |
} | |
}); | |
} | |
} | |
/** | |
* BeforeAll Asynchronous: used when there is a "done" argument | |
* defined in the callback. | |
*/ | |
function beforeAllAsync(callback) { | |
// Avoid registering multiple beforeEach callbacks. | |
if (!~history.indexOf(callback)) { | |
beforeEach(function (done) { | |
// Only execute if never executed before. | |
if (!~history.indexOf(callback)) { | |
history.push(callback); | |
callback(done); | |
} | |
}); | |
} | |
} | |
module.exports = beforeAll; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment