我应该在测试中测试undefined,null和空字符串

时间:2015-01-17 09:18:53

标签: javascript unit-testing jasmine

我的MaxNodeOccurs函数中有以下代码,用于检查参数是否有效,如果不是则抛出异常:

if (!nodeTypeParamIsValid()) {
    throw new Error('nodeType should be specified and should not be empty string');
}

function nodeTypeParamIsValid() {
    return !(ng.isUndefined(nodeType) || nodeType === null || nodeType === "");
}

现在我正在为此功能编写测试,我想知道我是否应该为nodeType param undefinednull或{{1}编写测试}}? 像这样:

empty string

或者仅仅为it('should throw exception if nodeType is undefined', function () { expect(MaxNodeOccursService.bind(null, undefined, 0)).toThrow(new Error('nodeType should be specified and should not be empty string')); }); it('should throw exception if nodeType is null', function () { expect(MaxNodeOccursService.bind(null, null, 0)).toThrow(new Error('nodeType should be specified and should not be empty string')); }); it('should throw exception if nodeType is an empty string', function () { expect(MaxNodeOccursService.bind(null, "", 0)).toThrow(new Error('nodeType should be specified and should not be empty string')); }); 写一个测试说法以确保投掷出来是否足够?

0 个答案:

没有答案