Я столкнулся с этой проблемой в своем полимерном компоненте и не могу понять, с чем столкнулся. Ниже приведен мой код:
<dom-module id="invoice-history">
<template>
<template is="dom-if" if="{{!_isHistoryPresent(invoiceListHistory)}}" >
<div class="no-message">{{noDataMessage}}</div>
</template>
<style include="invoice-history-styles"></style>
</template>
<script>
Polymer({
is: 'invoice-history',
properties: {
invoiceListHistory: Array
},
_isHistoryPresent: function (history) {
var hp = true;
if(history){
hp = history.every(function (invoice) {
return invoice.txnStatus == null;
});
}else {
this.message = "history not present";
}
return !hp;
}
});
</script>
</dom-module>
Ниже приведен мой тест (я написал результаты по ожиданиям):
<test-fixture id="invoice-history-fixture">
<template>
<invoice-history></invoice-history>
</template>
</test-fixture>
var invoiceListHistory = [good values]
before(function () {
iHistory = fixture('invoice-history-fixture');
});
context('dom manipulation tests', function () {
it('Should display no data message if there is no data', function (done) {
iHistory.setAttribute('invoice-list-history', invoiceListHistory);
iHistory.setAttribute('no-data-message', "It doesn't have data");
window.setTimeout(function () {
expect(Polymer.dom(iHistory.root).querySelector('.no-message').textContent).to.be.equal("XYZ"); // expected 'It doesn't have data' to equal 'XYZ'
expect(Polymer.dom(iHistory.root).querySelector('.no-message')).to.be.visible; // It passes
expect(qHistoryEl.message).to.be.equal('ABCD'); // expected 'history not present' to equal 'ABCD'
expect(window.getComputedStyle(Polymer.dom(iHistory.root).querySelector('.no-message'), null).getPropertyValue('visibility')).to.be.equal('jkl');
// expected 'visible' to equal 'jkl'
done();
}, 0);
});
});
Результат First expect(...) понятен. Но как проходит Second expect(...)?
И самое главное здесь, возможно, первопричина, в Third expect(...) говорит expected 'history not present' to equal 'ABCD'
. Это означает, что код переходит в блок else{} внутри метода _isHistoryPresent(). КАК?
Как проверить наличие динамически созданного элемента с помощью dom-if?