chai Assertion kaynağına bir göz atın, ancak tl; dr, Chai kendi zincirlenebilir yöntemlerini kendi iddi kitaplığında uyguladığıdır. Bununla birlikte, özel anahtar kelimeler, aşağıdaki koddaki gibi sadece sözdizimsel şekerlerdir. Orada aslında arar kadarıyla
/**
* ### Language Chains
*
* The following are provided as chainable getters to improve the readability
* of your assertions.
*
* **Chains**
*
* - to
* - be
* - been
* - is
* - that
* - which
* - and
* - has
* - have
* - with
* - at
* - of
* - same
* - but
* - does
*
* @name language chains
* @namespace BDD
* @api public
*/
[ 'to', 'be', 'been'
, 'is', 'and', 'has', 'have'
, 'with', 'that', 'which', 'at'
, 'of', 'same', 'but', 'does' ].forEach(function (chain) {
Assertion.addProperty(chain);
});
o özellikle tanımlar anahtar gibidir: Tam anlamıyla onlar eklenir ve zincirleme edilebilir ama hiçbir şey gerçekten tanımlanır sadece özellikleridir. Yani bir örnek anahtar kelime .to.be.true
Bunu kaynak kodunu kontrol edebilirsiniz
/**
* ### .true
*
* Asserts that the target is strictly (`===`) equal to `true`.
*
* expect(true).to.be.true;
*
* Add `.not` earlier in the chain to negate `.true`. However, it's often best
* to assert that the target is equal to its expected value, rather than not
* equal to `true`.
*
* expect(false).to.be.false; // Recommended
* expect(false).to.not.be.true; // Not recommended
*
* expect(1).to.equal(1); // Recommended
* expect(1).to.not.be.true; // Not recommended
*
* A custom error message can be given as the second argument to `expect`.
*
* expect(false, 'nooo why fail??').to.be.true;
*
* @name true
* @namespace BDD
* @api public
*/
Assertion.addProperty('true', function() {
this.assert(
true === flag(this, 'object')
, 'expected #{this} to be true'
, 'expected #{this} to be false'
, flag(this, 'negate') ? false : true
);
});
Ben javascript en [ '__defineGetter__'] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__) arayüzü üzerinden çalışır düşünebiliriz . –
Bu özellik, hiçbir şey yapmayan ve yalnızca gürültü ekleyen bir grup kukla özellik ekledikleri için işe yarıyor. Ben iddia ediyorum assert.isTrue() 'daha okunabilir ve kesinlikle böyle bir soruyu sormaz. –
@MattiVirkkunen Evet, insanlar kod isterlerse * İngilizce * ve değil * İngilizce-gibi * Kitap yazmaları gerektiğini düşünürüm – cat