Qunit异常测试

问题描述 投票:0回答:1

通过查看this question,我找不到当前问题的答案:

我有一个自定义异常(根据this guide设计):

let StrictOverwrite_destination_error = function(message) {
    var error = new Error(message);
    error.name = "utils_misc.StrictOverwrite_destination_error";    
    throw error;
};

我从函数strictOverwrite抛出:

function strictOverwrite ( destination, source, debug ) {

    // lots of code snipped

        else if ( !destination.hasOwnProperty( property ) && source.hasOwnProperty( property ) )
        {
            throw new StrictOverwrite_destination_error(
                "source.property exists, but destination.property doesn't" );
        }

    // more code snipped

    return destination;
}

错误和函数都在我的模块utils_misc中定义,尽管我的自定义异常定义不是从命名空间导出的。

这是我从strictOverwrite函数测试异常抛出的方法:

assert.throws(
    function() {
        utils_misc.strictOverwrite(c, c_dominator, false);
    },
    function(error) {
        return error.name === "utils_misc.StrictOverwrite_destination_error";
    }
);

但是,唉,Qunit不满意:

Expected:   

function( a ){
  [code]
}

Result:     

{
  "message": "property is not defined",
  "name": "ReferenceError"
}

Diff:   

function( a ){
  [code]{
  "message": "property is not defined",
  "name": "ReferenceError"
}

除了整件事不起作用之外,让我困惑的一件事是Qunit如何获得这个信息:"property is not defined"。这不完全是我的自定义StrictOverwrite_destination_error异常产生的消息。

qunit
1个回答
0
投票

写在这个问题中的测试代码非常合适。问题出在正在测试的应用程序代码中。

© www.soinside.com 2019 - 2024. All rights reserved.