当我运行测试用例(Jasmine)时收到此错误: 类型错误:未定义不是构造函数(评估“selectList.append(options)”)
我不确定为什么我的一些测试用例因此而失败。我的浏览器中的测试运行得非常好,但在本地失败(Maven 测试)。 (使用 Jasmine、Phantom JS)。
这里我有一个 editUser 按钮,单击该按钮会隐藏,并且会弹出(更新和取消)按钮,在此之前一直隐藏。
function userEditUser(id) {
var grandParent = $('#updateUser' + id).parent().parent().parent();
var updateUser = $('#updateUser' + id);
updateUser.siblings().removeClass('hideElement');
updateUser.addClass('hideElement');
var column_authority = document.getElementById('name1');
var name_list = ["A", "B", "C"];
var selectList = document.createElement('select');
selectList.setAttribute('name', 'userName');
for(var i = 0; i <name_list.length; i++){
var options = document.createElement('option');
options.text=name_list[i];
selectList.append(options);
}
column_authority.appendChild(selectList);
失败的测试用例之一:
it('update button should not have a css class hideElement', function () {
$('button[name="updateUser"]').click();
expect($('button[name="updateBtn"]')).not.toHaveClass('hideElement');
});
但是函数此时失败了: selectList.append(选项)
最佳答案
我猜 Phantom JS 不识别追加函数。现在一切对我来说一切顺利,
all I did is changed
selectList.append(options); to
selectList.appendChild(options);
此更改回答了我所有失败的测试用例。 非常感谢你们有兴趣为我的问题提供解决方案。
关于javascript - 类型错误 : Undefined is not a constuctor (evaluating 'selectList.append(options)' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47544344/