boar-angular2-testing
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -11,8 +11,14 @@ import { RequestMethod } from '@angular/http'; | ||
private _response; | ||
private _responseCode; | ||
private _errorResponse; | ||
constructor(expectedRequest?: IExpectedRequest); | ||
response: any; | ||
responseCode: number; | ||
errorResponse: any; | ||
respondWith({body, status}: { | ||
body: any; | ||
status: number; | ||
}): void; | ||
respondWithSuccess(response?: any): void; | ||
respondWithError(error?: string): void; | ||
respondWithError(error?: any): void; | ||
match(connection: MockConnection): boolean; | ||
@@ -19,0 +25,0 @@ _matchMethod(connection: MockConnection): boolean; |
@@ -14,2 +14,9 @@ "use strict"; | ||
}); | ||
Object.defineProperty(Expectation.prototype, "responseCode", { | ||
get: function () { | ||
return this._responseCode; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Expectation.prototype, "errorResponse", { | ||
@@ -22,2 +29,7 @@ get: function () { | ||
}); | ||
Expectation.prototype.respondWith = function (_a) { | ||
var _b = _a.body, body = _b === void 0 ? null : _b, _c = _a.status, status = _c === void 0 ? 200 : _c; | ||
this._response = body; | ||
this._responseCode = status; | ||
}; | ||
Expectation.prototype.respondWithSuccess = function (response) { | ||
@@ -24,0 +36,0 @@ if (response === void 0) { response = null; } |
@@ -161,3 +161,6 @@ "use strict"; | ||
else { | ||
connectionToFlush.mockRespond(new http_1.Response(new http_1.ResponseOptions({ body: nextExpectation.response }))); | ||
connectionToFlush.mockRespond(new http_1.Response(new http_1.ResponseOptions({ | ||
body: nextExpectation.response, | ||
status: nextExpectation.responseCode | ||
}))); | ||
} | ||
@@ -164,0 +167,0 @@ this._pendingConnections = this._pendingConnections.filter(function (connection) { return connectionToFlush !== connection; }); |
@@ -52,2 +52,22 @@ "use strict"; | ||
}); | ||
it('should respond with the given error if the url matches and an error was set', function () { | ||
var _a = createModule(), backend = _a.backend, http = _a.http; | ||
var error = new Error('test'); | ||
var URL = 'http://test.me.org/index.html'; | ||
backend.whenGET(URL).respondWithError(error); | ||
var response = null; | ||
http.get(URL).map(function (res) { return res.json(); }).subscribe(function () { }, function (err) { return response = err; }); | ||
backend.flushNext(); | ||
chai_1.expect(response).to.eql(error); | ||
}); | ||
it('should respond with the given status code if the url matches', function () { | ||
var _a = createModule(), backend = _a.backend, http = _a.http; | ||
var dummyResponse = { 'yo': 'I am a json from the server ' }; | ||
var URL = 'http://test.me.org/index.html'; | ||
backend.whenGET(URL).respondWith({ body: dummyResponse, status: 202 }); | ||
var status = null; | ||
http.get(URL).subscribe(function (r) { return status = r.status; }); | ||
backend.flushNext(); | ||
chai_1.expect(status).to.eql(202); | ||
}); | ||
it("should thrown an error if the expected url doesn't match", function () { | ||
@@ -54,0 +74,0 @@ var _a = createModule(), backend = _a.backend, http = _a.http; |
@@ -42,3 +42,3 @@ { | ||
}, | ||
"version": "2.0.1" | ||
"version": "2.1.0" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49472
636