flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
56 lines • 2.35 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const response_1 = require("./response");
const url_1 = require("url");
const value_1 = require("./value");
;
class ImageResponse extends response_1.GenericResponse {
get length() {
return this._wrapAsValue(this.imageProperties.length, 'Image Size');
}
get url() {
return this._wrapAsValue(this.imageProperties.url, 'URL of Image');
}
get path() {
return this._wrapAsValue(new url_1.URL(this.imageProperties.url).pathname, 'URL Path of Image');
}
get type() {
return response_1.ResponseType.image;
}
get typeName() {
return 'Image';
}
constructor(scenario, response) {
super(scenario, response);
this.imageProperties = JSON.parse(response.body);
this.context.assert('MIME Type matches expected value for an image', this.imageProperties.mime).startsWith('image/');
}
evaluate(context, callback) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error('Evaluate does not support images.');
});
}
find(propertyName) {
return __awaiter(this, void 0, void 0, function* () {
return new value_1.Value(typeof this.imageProperties[propertyName] !== 'undefined' ?
this.imageProperties[propertyName] :
null, this.context, `${propertyName} of Image`);
});
}
findAll(propertyName) {
return __awaiter(this, void 0, void 0, function* () {
const value = yield this.find(propertyName);
return value.isNull() ? [] : [value];
});
}
}
exports.ImageResponse = ImageResponse;
//# sourceMappingURL=imageresponse.js.map