Jestem nowy w przypadku testowego jaśmin starałem się zrobić sprawdzian jaśmin dla modułu wyboru po wykonaniu tej właściwość stylu jest coraz niezdefiniowanyJak zrobić sprawdzian jaśmin własności display none css wykorzystaniem documet.getElementById i 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';
};
Moja testcase jest
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');
});
});
Po wykonaniu tej czynności mam czuło i kod do beforEach
usunięteTypeError: Cannot read property 'style' of undefined
proszę mnie poprawić, jeśli zrobiłem źle
Własność "styl", której używałeś tyle czasu? w miejscu, gdzie ten błąd rzeczywiście przyszedł? –
@VikrantKashyap it ('expand the flight details part', function() { flightselection.expandFlightDetails(); expect (document.body.getElementsByClassName ('flight-details-container') [0] .style.display). toEqual ("none"); }); dla tego przypadku testowego otrzymuję ten błąd –
Czy dołączasz plik html, który ma element z klasą "flight-details-container". ? – rajesh