在Dalek.js中将测试写成函数

Writing tests as functions in Dalek.js

本文关键字:函数 测试 Dalek js      更新时间:2023-09-26

我一直在使用Dalek.js进行测试,并且一直很喜欢它。我想从我的一个文件中进行一些测试,并将它们放在一个单独的"common_tests.js"文件中,以便我可以在其他地方使用它们,而无需复制代码。然而,每当我尝试将测试代码移出主文件时,测试就无法正确执行—我得到两次"RUNNING test - '[test NAME]'"消息。第一个什么都不做,第二个在试图打开页面时立即挂起。我做错了什么吗?

我的代码是这样的格式:

在common_tests.js:

module.exports = {
    testFunction: function(test) {
        test
            .open("www.google.com")
            // other testing stuff here that's fine when in the other file
        .done();
}

在我的测试文件中:

var common = require('../common_tests.js");
module.exports = {
    'Trying to test with functions': function(test) {
        common.testFunction(test);
        test.done();
     }
} 

我从未使用过DalekJS,但看起来您正在调用test.done()两次:一次在您在common_tests.js中编写的共享函数中,然后在您的测试文件中,在调用公共函数之后。

我应该这样写测试文件:
var common = require('../common_tests.js');
module.exports = {
    'Trying to test with functions': common.testFunction,
};