簡體   English   中英

每次之后需要茉莉花測試幫助

[英]Jasmine test help needed afterEach

我有一個使用jQuery構建的邏輯,每個邏輯使用兩個循環。 我不確定如何為它編寫茉莉花測試。

這是我的代碼/邏輯:

<div id="mj">
  <div class="commonclass">
    Item 1
  </div>
  <div class="commonclass">
    Item 2
  </div>
  <div class="commonclass">
    Item 3
  </div>
</div>

jQuery的:

var filterArray = ['Item', 'Block', 'Item 3'];

$.each($('.commonclass'), function(i, v) {
  var matching = false;
  $.each(filterArray, function(j, w) {
    if ($(v).text().trim() == w)
      matching = true;
  });
  if (matching)
    $(v).remove();
});

邏輯:

div元素中的文本不應與filterarray值匹配。 如果元素匹配,則應將其刪除。

這是我的茉莉花測試代碼。 (添加部分)

describe('Delete matching element', function() {
        beforeAll(function() {
            elementsEl = element(SelectorData.selectors.elementSelector);
            elementValueEl = element(SelectorData.selectors.elementTitleSelector);
            bodyDocumentEl = element(SelectorData.selectors.body);
            bodyDocumentValues = SelectorData.values;
        });

        afterEach( function() {

            if (elementValueEl.value == bodyDocumentValues.value) {
                document.body.removeChild(elementsEl);
            }

        });

        it('delete the element', function() {
            expect(elementsEl.isPresent()).toBe(false);

        });
    });

讓我知道我在做什么錯。 JSfiddle:https://jsfiddle.net/dmahendranme/g1L2Lzm1/

嘗試這個,

$(function(){    
    var filterArray = ['Item', 'Block', 'Item 3'];
    $('.commonclass').each(function(k,v){        
        if($.inArray($.trim($(v).text()), filterArray) > 0){
            $(this).remove()
        }
    });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM