Javascript html元素的单元测试用例
我无法使用Jasmine在单元测试中获取html元素值。 JavaScript代码:Javascript html元素的单元测试用例,javascript,jquery,jasmine,jasmine-jquery,Javascript,Jquery,Jasmine,Jasmine Jquery,我无法使用Jasmine在单元测试中获取html元素值。 JavaScript代码: $scope.close = function () { $scope.success = false; $('#current, #new').val(''); // Need to test this }; it('close method', function() { scope.close(); expect($('#current')).toContain
$scope.close = function () {
$scope.success = false;
$('#current, #new').val(''); // Need to test this
};
it('close method', function() {
scope.close();
expect($('#current')).toContain(''); //unable to get the value ->return undefined
});
茉莉花代码:
$scope.close = function () {
$scope.success = false;
$('#current, #new').val(''); // Need to test this
};
it('close method', function() {
scope.close();
expect($('#current')).toContain(''); //unable to get the value ->return undefined
});
错误:
$scope.close = function () {
$scope.success = false;
$('#current, #new').val(''); // Need to test this
};
it('close method', function() {
scope.close();
expect($('#current')).toContain(''); //unable to get the value ->return undefined
});
TypeError:“undefined”不是函数(正在计算“haystack.indexOf(Pine针)”)
请帮助我解决这个问题。您正在尝试对jQuery节点集合执行
.toContain
测试,该集合不是数组,因此它没有您的错误提到的.indexOf
方法。如果您试图测试使用.val()
设置的值,请改为:
expect($('#current').val()).toEqual('');