我想在我所有的测试套件中共享一个beforeAll()方法。有办法做到这一点吗?(我的意思是,不需要在所有测试套件中编写相同的beforeAll/afterAll方法)
谢谢,
发布于 2017-01-12 13:56:09
听起来您想要有一个可重用的beforeAll方法,该方法出现在所有等级库文件中。在下面的示例中,您仍然需要将函数somefile.beforeAll传递给jasmine beforeAll方法:
somefile.js
exports.beforeAll = function() {
// cool stuff here.
}spec.js
var somefile = require('./path/to/somefile');
describe('some cool browser thing', function() {
// instead of beforeAll(function() { });
// send in your function here.
beforeAll(somefile.beforeAll);
});如果您需要在所有规范文件之前执行一次此操作,请考虑使用plugins。
发布于 2017-01-12 17:44:03
如果你正在使用像gulp这样的任务运行器,你可以定义一个beforeAll函数,并将其封装在一个gulp任务中,并在内部调用每个套件任务之前作为先决条件任务,如下所示:
gulp.task('SuiteA', ['BeforeAll'], function () {
executeSuiteA_Tests('parameters'); // before calling this 'BeforeAll' task will be called
});https://stackoverflow.com/questions/41601377
复制相似问题