UNPKG

@rxx/http

Version:
39 lines (38 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var http_handler_1 = require("./http-handler"); var HttpHandlerMock = (function (_super) { tslib_1.__extends(HttpHandlerMock, _super); function HttpHandlerMock(methods, advices) { var _this = _super.call(this, advices) || this; _this.methods = methods; _this.fetchFunction = function (url, request) { return new Promise(function (resolve, reject) { setTimeout(function () { var method = _this.methods[(request.method || 'get').toLowerCase()]; if (typeof method === 'function') { var fn = method; try { return resolve(fn(url, request)); } catch (e) { return reject(e); } } resolve(new Response(request.body, { status: 200, statusText: 'OK' })); }, 100); }); }; return _this; } Object.defineProperty(HttpHandlerMock.prototype, "fetch", { get: function () { return this.fetchFunction; }, enumerable: true, configurable: true }); return HttpHandlerMock; }(http_handler_1.HttpHandler)); exports.HttpHandlerMock = HttpHandlerMock;