Not: Bu çözüm, Jasmine v2.0'dan önceki sürümler için sözdizimi içerir. Özel matchers hakkında daha fazla bilgi için şimdi, bakınız: https://jasmine.github.io/2.0/custom_matcher.html
Matchers.js tek bir 'sonuç değiştirici' ile çalışan tek - not
:
çekirdek/Spec.js:
jasmine.Spec.prototype.expect = function(actual) {
var positive = new (this.getMatchersClass_())(this.env, actual, this);
positive.not = new (this.getMatchersClass_())(this.env, actual, this, true);
return positive;
çekirdek/Matchers.js:
jasmine.Matchers = function(env, actual, spec, opt_isNot) {
...
this.isNot = opt_isNot || false;
}
...
jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
return function() {
...
if (this.isNot) {
result = !result;
}
}
}
Gerçekten de kendi eşleştiricinizi (before
veya bloğu içinden doğru this
için) yazmanız gerekiyor. Örneğin:
this.addMatchers({
toBeAnyOf: function(expecteds) {
var result = false;
for (var i = 0, l = expecteds.length; i < l; i++) {
if (this.actual === expecteds[i]) {
result = true;
break;
}
}
return result;
}
});
Dokümantasyonu kontrol ettim ve bazı kodları denedim, ama sanırım "kolayca" özür dilemiyoruz. Ama bulduğum şeye göre kendi "zincirlenebilir" eşleştiricinizi yaratabilirsiniz. – Magus