unmock-core
Version:
[][npmjs] [](https://circleci.com/gh/unmock/unmock-js) [](h
97 lines • 5.03 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const sinon_1 = require("sinon");
const decorate_1 = require("../decorate");
exports.decorators = {
with(matcher) {
return decorate_1.decorateSpy(this.withArgs(matcher));
},
withMethod(method) {
return this.with(sinon_1.match({ method }));
},
postRequestHost(matcher) {
const methodMatcher = sinon_1.match({ method: "post" });
const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher;
const spyWithMatcher = this.with(fullMatcher);
decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postHost" });
return spyWithMatcher.firstCall.args[0].host;
},
postRequestBody(matcher) {
const methodMatcher = sinon_1.match({ method: "post" });
const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher;
const spyWithMatcher = this.with(fullMatcher);
decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postRequestBody" });
return spyWithMatcher.firstCall.args[0].body;
},
postResponseBody(matcher) {
const methodMatcher = sinon_1.match({ method: "post" });
const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher;
const spyWithMatcher = this.with(fullMatcher);
decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "postResponseBody" });
return spyWithMatcher.firstCall.returnValue.body;
},
getRequestHost(matcher) {
const methodMatcher = sinon_1.match({ method: "get" });
const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher;
const spyWithMatcher = this.with(fullMatcher);
decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getHost" });
return spyWithMatcher.firstCall.args[0].host;
},
getRequestBody(matcher) {
const methodMatcher = sinon_1.match({ method: "get" });
const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher;
const spyWithMatcher = this.with(fullMatcher);
decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getRequestBody" });
return spyWithMatcher.firstCall.args[0].body;
},
getResponseBody(matcher) {
const methodMatcher = sinon_1.match({ method: "get" });
const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher;
const spyWithMatcher = this.with(fullMatcher);
decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "getResponseBody" });
return spyWithMatcher.firstCall.returnValue.body;
},
putRequestHost(matcher) {
const methodMatcher = sinon_1.match({ method: "put" });
const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher;
const spyWithMatcher = this.with(fullMatcher);
decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putHost" });
return spyWithMatcher.firstCall.args[0].host;
},
putRequestBody(matcher) {
const methodMatcher = sinon_1.match({ method: "put" });
const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher;
const spyWithMatcher = this.with(fullMatcher);
decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putRequestBody" });
return spyWithMatcher.firstCall.args[0].body;
},
putResponseBody(matcher) {
const methodMatcher = sinon_1.match({ method: "put" });
const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher;
const spyWithMatcher = this.with(fullMatcher);
decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "putResponseBody" });
return spyWithMatcher.firstCall.returnValue.body;
},
deleteRequestHost(matcher) {
const methodMatcher = sinon_1.match({ method: "delete" });
const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher;
const spyWithMatcher = this.with(fullMatcher);
decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteHost" });
return spyWithMatcher.firstCall.args[0].host;
},
deleteRequestBody(matcher) {
const methodMatcher = sinon_1.match({ method: "delete" });
const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher;
const spyWithMatcher = this.with(fullMatcher);
decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteRequestBody" });
return spyWithMatcher.firstCall.args[0].body;
},
deleteResponseBody(matcher) {
const methodMatcher = sinon_1.match({ method: "delete" });
const fullMatcher = matcher ? methodMatcher.and(matcher) : methodMatcher;
const spyWithMatcher = this.with(fullMatcher);
decorate_1.verifyOnlyOneCall({ spy: spyWithMatcher, errPrefix: "deleteResponseBody" });
return spyWithMatcher.firstCall.returnValue.body;
},
};
//# sourceMappingURL=index.js.map