mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-03-29 00:18:20 +08:00
Changes to httpBackend to conform to angular documentation here: https://code.angularjs.org/1.3.16/docs/api/ngMock/service/$httpBackend
Mainly add the option to pass a function in the url parameter. Also updated IRequestHandler interface respond function to return an IRequestHandler, and updated overloads. Also added documentation.
This commit is contained in:
34
angularjs/angular-mocks.d.ts
vendored
34
angularjs/angular-mocks.d.ts
vendored
@@ -1,7 +1,6 @@
|
||||
// Type definitions for Angular JS 1.3 (ngMock, ngMockE2E module)
|
||||
// Project: http://angularjs.org
|
||||
// Definitions by: Diego Vilar <http://github.com/diegovilar>
|
||||
// Definitions by: Tony Curtis <http://github.com/daltin>
|
||||
// Definitions by: Diego Vilar <http://github.com/diegovilar>, Tony Curtis <http://github.com/daltin>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="angular.d.ts" />
|
||||
@@ -119,7 +118,6 @@ declare module angular {
|
||||
*/
|
||||
verifyNoOutstandingRequest(): void;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new request expectation.
|
||||
* Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
|
||||
@@ -267,7 +265,15 @@ declare module angular {
|
||||
}
|
||||
|
||||
export module mock {
|
||||
|
||||
// this interface makes it possible to diferentiate between a function parameter (in the first overload for IRequestHandler)
|
||||
// and the data: string | Object parameter in the second overload. Since a function is an object, and the first overload
|
||||
// takes one function param and the second overload takes a data string or Object with the other two parameters being optional,
|
||||
// there was no type difference between respond((a,b,c,d) => {}) and respond({}). Using the JsonResponseData interface
|
||||
// as a type creates a difference in the signatures changing data: string | Object to data: string | JsonResponseData
|
||||
interface JsonResponseData extends Object {
|
||||
[key: string] : any;
|
||||
}
|
||||
|
||||
// returned interface by the the mocked HttpBackendService expect/when methods
|
||||
interface IRequestHandler {
|
||||
|
||||
@@ -276,7 +282,16 @@ declare module angular {
|
||||
* Returns the RequestHandler object for possible overrides.
|
||||
* @param func Function that receives the request HTTP method, url, data, and headers and returns an array containing response status (number), data, headers, and status text.
|
||||
*/
|
||||
respond(func: ((method: string, url: string, data?: string | Object, headers?: Object) => [number, string, Object, string])): IRequestHandler;
|
||||
respond(func: ((method: string, url: string, data: string | Object, headers: Object) => [number, string | Object, Object, string])): IRequestHandler;
|
||||
|
||||
/**
|
||||
* Controls the response for a matched request using the HTTP status code 200 and supplied static data to construct the response.
|
||||
* Returns the RequestHandler object for possible overrides.
|
||||
* @param data Data to add to the response.
|
||||
* @param headers Headers object to add to the response.
|
||||
* @param responseText Response text to add to the response.
|
||||
*/
|
||||
respond(data: string | JsonResponseData, headers?: Object, responseText?: string): IRequestHandler;
|
||||
|
||||
/**
|
||||
* Controls the response for a matched request using supplied static data to construct the response.
|
||||
@@ -288,15 +303,6 @@ declare module angular {
|
||||
*/
|
||||
respond(status: number, data: string | Object, headers?: Object, responseText?: string): IRequestHandler;
|
||||
|
||||
/**
|
||||
* Controls the response for a matched request using the HTTP status code 200 and supplied static data to construct the response.
|
||||
* Returns the RequestHandler object for possible overrides.
|
||||
* @param data Data to add to the response.
|
||||
* @param headers Headers object to add to the response.
|
||||
* @param responseText Response text to add to the response.
|
||||
*/
|
||||
respond(data: string | {}, headers?: Object, responseText?: string): IRequestHandler;
|
||||
|
||||
// Available when ngMockE2E is loaded
|
||||
/**
|
||||
* Any request matching a backend definition or expectation with passThrough handler will be passed through to the real backend (an XHR request will be made to the server.)
|
||||
|
||||
Reference in New Issue
Block a user