Tôi mới vào các trường hợp thử nghiệm hoa nhài Tôi cố gắng để làm trường hợp thử nghiệm hoa nhài cho module lựa chọn sau khi làm sở hữu phong cách này hiển thị không có css là nhận được xác địnhLàm thế nào để làm trường hợp thử nghiệm hoa nhài cho bất động sản sử dụng documet.getElementById và getElementsByClassName
function Selection() {
}
Selection.prototype.expandFlightDetails = function() {
document.getElementsByClassName("flight-details-container").style.display = 'none';
document.getElementById("expandedFlightDetails").style.display = 'block';
};
Selection.prototype.hideFlightDetails = function() {
document.getElementById("expandedFlightDetails").style.display = 'none';
document.getElementsByClassName("flight-details-container").style.display = 'block';
};
testcase của tôi là
describe("selection module", function() {
var selection;
beforeEach(function() {
selection= new Selection();
});
afterEach(function() {
});
it('expand the flight details part ' , function(){
selection.expandFlightDetails();
expect(document.body.getElementsByClassName('flight-details-container')[0].style.display).toEqual('none');
});
xit('hide the flight details part ', function(){
selection.hideFlightDetails();
expect(document.getElementById('expandedFlightDetails').style.display).toEqual('none');
});
});
Sau khi thực hiện này tôi geting và loại bỏ mã để beforEach
TypeError: Cannot read property 'style' of undefined
hãy sửa tôi nếu tôi đã làm sai
thuộc tính 'style' bạn đã sử dụng quá nhiều thời gian? tại nơi lỗi này thực sự đến? –
@VikrantKashyap nó ('mở rộng chi tiết chuyến bay một phần', chức năng() { flightselection.expandFlightDetails(); mong đợi (document.body.getElementsByClassName ('flight-details-container') [0] .style.display). toEqual ('none'); }); cho trường hợp kiểm tra này, tôi nhận được lỗi này –
Bạn có bao gồm tệp html có yếu tố với lớp "chi tiết chuyến bay-container" hay không. ? – rajesh