flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
165 lines • 5.85 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValuePromise = void 0;
const util_1 = require("./util");
const assertion_promise_1 = require("./assertion/assertion-promise");
function assertionMethod(target, methodName, descriptor) {
descriptor.value = function (...args) {
const valuePromise = util_1.cast(this);
return new assertion_promise_1.AssertionPromise((resolve) => valuePromise.then((value) => {
const assertion = value.assert();
resolve(assertion[methodName].apply(assertion, args));
}));
};
}
class ValuePromise extends Promise {
constructor(executor) {
super(executor);
this.rename = (newName) => this.toValuePromise("rename", newName);
this.clear = () => this.toValuePromise("clear");
this.clearThenType = (text, opts) => this.toValuePromise("clearThenType", text, opts);
this.type = (text, opts) => this.toValuePromise("type", text, opts);
this.assert = (message) => {
return new assertion_promise_1.AssertionPromise((resolve) => this.then((value) => resolve(value.assert(message))));
};
this.exists = () => this._promisifyMethod("exists");
}
static execute(callback) {
return ValuePromise.wrap(callback());
}
static wrap(value) {
return new ValuePromise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
try {
resolve(yield value);
}
catch (ex) {
reject(ex);
}
}));
}
get is() {
return this._promisifyProperty("is");
}
get not() {
return this._promisifyAssertProperty("not");
}
equals(value) {
return util_1.cast(null);
}
exactly(value) {
return util_1.cast(null);
}
like(value) {
return util_1.cast(null);
}
contains(value) {
return util_1.cast(null);
}
greaterThan(value) {
return util_1.cast(null);
}
lessThan(value) {
return util_1.cast(null);
}
greaterThanOrEquals(value) {
return util_1.cast(null);
}
lessThanOrEquals(value) {
return util_1.cast(null);
}
between(min, max) {
return util_1.cast(null);
}
matches(value) {
return util_1.cast(null);
}
startsWith(value) {
return util_1.cast(null);
}
endsWith(value) {
return util_1.cast(null);
}
includes(value) {
return util_1.cast(null);
}
_promisifyAssertMethod(method, args = []) {
return new Promise((r) => this.then((value) => {
const assertion = value.assert();
r(assertion[method].apply(assertion, args));
}));
}
_promisifyAssertProperty(property) {
return new Promise((r) => this.then((v) => r(v.assert()[property])));
}
_promisifyMethod(method, args = []) {
return __awaiter(this, void 0, void 0, function* () {
const value = yield this;
return value[method].apply(value, args);
});
}
_promisifyProperty(property) {
return new Promise((r) => this.then((v) => r(v[property])));
}
toValuePromise(method, ...args) {
return ValuePromise.execute(() => __awaiter(this, void 0, void 0, function* () {
const value = yield this;
return value[method].apply(value, args);
}));
}
}
__decorate([
assertionMethod
], ValuePromise.prototype, "equals", null);
__decorate([
assertionMethod
], ValuePromise.prototype, "exactly", null);
__decorate([
assertionMethod
], ValuePromise.prototype, "like", null);
__decorate([
assertionMethod
], ValuePromise.prototype, "contains", null);
__decorate([
assertionMethod
], ValuePromise.prototype, "greaterThan", null);
__decorate([
assertionMethod
], ValuePromise.prototype, "lessThan", null);
__decorate([
assertionMethod
], ValuePromise.prototype, "greaterThanOrEquals", null);
__decorate([
assertionMethod
], ValuePromise.prototype, "lessThanOrEquals", null);
__decorate([
assertionMethod
], ValuePromise.prototype, "between", null);
__decorate([
assertionMethod
], ValuePromise.prototype, "matches", null);
__decorate([
assertionMethod
], ValuePromise.prototype, "startsWith", null);
__decorate([
assertionMethod
], ValuePromise.prototype, "endsWith", null);
__decorate([
assertionMethod
], ValuePromise.prototype, "includes", null);
exports.ValuePromise = ValuePromise;
//# sourceMappingURL=value-promise.js.map