问题描述
我发现了很多类似的问题,但是解决方案没有用。
我遇到了Jasmine和Jasmine-Jquery检测到已添加到灯具的类的麻烦。测试不断失败,表明该类不存在...但是,当我登录治具进行控制台时,该类就在那里了! 我是茉莉花测试的新手,所以我敢肯定,有一些简单的事情,例如检测我缺少的灯具更改,我们将不胜感激!
灯具的相关部分:
<button type="submit" class="card-image btn btn-link border border-white border-4 m-1 p-0" style="background-image: url(/media/portraits/thumbs/brianna-mills-2qoyI8Mewe0-unsplash_Cropped.jpeg);" data-image-full="/media/portraits/brianna-mills-2qoyI8Mewe0-unsplash_Cropped.jpg">
<img src="/media/portraits/thumbs/brianna-mills-2qoyI8Mewe0-unsplash_Cropped.jpeg" class="card-img-top img-fluid" alt="Seventh Person" />
</button>
js
文件:
function lazyLoad() {
const cardImages = document.querySelectorAll(".card-image");
// loop over each image
cardImages.forEach(function (cardImage) {
const imageUrl = cardImage.getAttribute("data-image-full");
const contentimage = cardImage.querySelector("img");
// change src to full res image
contentimage.src = imageUrl;
// fires the swap function on load
contentimage.addEventListener("load",function () {
// sets the background as the full res image
cardImage.style.backgroundImage = "url(" + imageUrl + ")";
// applies class for a smooth transition to the gallery images
cardImage.classList.add("is-loaded");
});
});
和规格测试
jasmine.getFixtures().fixturesPath = '/static/js/jasmine/spec/javascripts/fixtures'
beforeEach(function() {
loadFixtures('myfixture.html')
$.fx.off = true;
});
it("Should add the is-loaded class",function () {
lazyLoad()
$(".card-image > img").trigger( "load" )
console.log(($(`.card-image`))[0])
expect($(`.card-image`)[0]).toHaveAttr('class','is-loaded')
})
我有另一个测试来确认load
被触发,我尝试使用间谍,不同的选择器等,但是测试始终失败,并返回Expected <button type="submit" class="card-image btn btn-link border border-white border-4 m-1 p-0"... to have Class 'is-loaded'
。
我不知道我想念什么。有什么建议吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)