cybernaut
Version:
Reliable, zero configuration end-to-end testing in BDD-style.
60 lines • 2.18 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const deepStrictEqual = require("deep-strict-equal");
class PredicateBuilder {
constructor() {
this._at = '';
this._be = '';
this._not = '';
}
get at() {
this._at = ' at';
return this;
}
get be() {
this._be = ' be';
return this;
}
get not() {
this._not = ' not';
return this;
}
contain(expectedValue) {
const description = { template: 'contain {}', args: [expectedValue] };
return this._build(description, actualValue => actualValue.indexOf(expectedValue) > -1);
}
equal(expectedValue) {
const description = { template: 'equal {}', args: [expectedValue] };
return this._build(description, actualValue => deepStrictEqual(actualValue, expectedValue));
}
match(regex) {
const description = { template: 'match {}', args: [regex] };
return this._build(description, actualValue => regex.test(actualValue));
}
above(expectedValue) {
const description = { template: 'above {}', args: [expectedValue] };
return this._build(description, actualValue => actualValue > expectedValue);
}
least(expectedValue) {
const description = { template: 'least {}', args: [expectedValue] };
return this._build(description, actualValue => actualValue >= expectedValue);
}
below(expectedValue) {
const description = { template: 'below {}', args: [expectedValue] };
return this._build(description, actualValue => actualValue < expectedValue);
}
most(expectedValue) {
const description = { template: 'most {}', args: [expectedValue] };
return this._build(description, actualValue => actualValue <= expectedValue);
}
_build({ args, template }, test) {
return {
description: {
template: `should${this._not}${this._be}${this._at} ${template}`, args
},
test: this._not ? value => !test(value) : test
};
}
}
exports.PredicateBuilder = PredicateBuilder;
//# sourceMappingURL=predicate.js.map