mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Added definitions for protractor-http-mock.
This commit is contained in:
@@ -0,0 +1,211 @@
|
||||
/// <reference path="./protractor-http-mock.d.ts" />
|
||||
|
||||
function TestConfig() {
|
||||
mock.config = {
|
||||
rootDirectory: 'root',
|
||||
protractorConfig: 'protractor.conf.js'
|
||||
};
|
||||
}
|
||||
|
||||
function TestCtorOverloads() {
|
||||
let noParam: mock.ProtractorHttpMock = mock();
|
||||
let emptyArray: mock.ProtractorHttpMock = mock([]);
|
||||
let skipDefaults: mock.ProtractorHttpMock = mock([], true);
|
||||
|
||||
let del: mock.requests.Delete<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'DELETE'
|
||||
},
|
||||
response: {
|
||||
status: 400,
|
||||
data: 1
|
||||
}
|
||||
};
|
||||
let put: mock.requests.Put<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'PUT'
|
||||
},
|
||||
response: {
|
||||
status: 400,
|
||||
data: 1
|
||||
}
|
||||
};
|
||||
let mocks: mock.ProtractorHttpMock = mock([del, put]);
|
||||
}
|
||||
|
||||
function TestTeardown() {
|
||||
mock.teardown();
|
||||
}
|
||||
|
||||
function TestRequestsMade() {
|
||||
let values: Array<mock.ReceivedRequest>;
|
||||
mock.requestsMade().then(v => values = v);
|
||||
}
|
||||
|
||||
function TestClearRequests() {
|
||||
let promiseValue: boolean;
|
||||
mock.clearRequests().then(value => {
|
||||
promiseValue = value;
|
||||
});
|
||||
}
|
||||
|
||||
function TestGetRequestDefinitions() {
|
||||
let getMinium: mock.requests.Get<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'GET'
|
||||
},
|
||||
response: {
|
||||
data: 1,
|
||||
status: 500
|
||||
}
|
||||
};
|
||||
|
||||
let getParams: mock.requests.Get<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'GET',
|
||||
params: {
|
||||
param1: 'param1',
|
||||
param2: 2
|
||||
}
|
||||
},
|
||||
response: {
|
||||
data: 1,
|
||||
status: 500
|
||||
}
|
||||
};
|
||||
|
||||
let post: mock.requests.Post<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'POST'
|
||||
},
|
||||
response: {
|
||||
data: 1,
|
||||
status: 500
|
||||
}
|
||||
};
|
||||
|
||||
let getQueryString: mock.requests.Get<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'GET',
|
||||
queryString: {
|
||||
query1: 'query1',
|
||||
query2: 2
|
||||
}
|
||||
},
|
||||
response: {
|
||||
data: 1,
|
||||
status: 500
|
||||
}
|
||||
};
|
||||
|
||||
let getHeaders: mock.requests.Get<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'GET',
|
||||
headers: {
|
||||
head1: 'head1',
|
||||
head2: 'head2'
|
||||
}
|
||||
},
|
||||
response: {
|
||||
data: 1,
|
||||
status: 500
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function TestPostRequestDefinitions() {
|
||||
let post: mock.requests.Post<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'POST'
|
||||
},
|
||||
response: {
|
||||
data: 1,
|
||||
status: 500
|
||||
}
|
||||
};
|
||||
|
||||
let postData: mock.requests.PostData<number, string> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'POST',
|
||||
data: 'data'
|
||||
},
|
||||
response: {
|
||||
data: 1,
|
||||
status: 500
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function TestHeadRequestDefinitions() {
|
||||
let head: mock.requests.Head<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'HEAD'
|
||||
},
|
||||
response: {
|
||||
status: 500,
|
||||
data: 1
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function TestDeleteRequestDefinitions() {
|
||||
let del: mock.requests.Delete<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'DELETE'
|
||||
},
|
||||
response: {
|
||||
status: 500,
|
||||
data: 1
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function TestPutRequestDefinitions() {
|
||||
let put: mock.requests.Put<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'PUT'
|
||||
},
|
||||
response: {
|
||||
status: 500,
|
||||
data: 1
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function TestPatchRequestDefinitions() {
|
||||
let patch: mock.requests.Patch<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'PATCH'
|
||||
},
|
||||
response: {
|
||||
status: 500,
|
||||
data: 1
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function TestJsonpRequestDefinitions() {
|
||||
let jsonp: mock.requests.Jsonp<number> = {
|
||||
request: {
|
||||
path: 'path',
|
||||
method: 'JSONP'
|
||||
},
|
||||
response: {
|
||||
status: 500,
|
||||
data: 1
|
||||
}
|
||||
};
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
// Type definitions for protractor-http-mock
|
||||
// Project: https://github.com/atecarlos/protractor-http-mock
|
||||
// Definitions by: Crevil <https://github.com/Crevil>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../selenium-webdriver/selenium-webdriver.d.ts" />
|
||||
|
||||
declare module mock {
|
||||
interface ProtractorHttpMock {
|
||||
/**
|
||||
* Instantiate mock module. This must be done before the browser connects.
|
||||
*
|
||||
* @param mocks An array of mock modules to load into the application.
|
||||
* @param skipDefaults Set true to skip loading of default mocks.
|
||||
*/
|
||||
<T>(mocks?: Array<requests.BaseRequest<T>>, skipDefaults?: boolean): ProtractorHttpMock;
|
||||
|
||||
/**
|
||||
* Clean up.
|
||||
* Typically done in the afterEach call to ensure the teardown
|
||||
* is executed regardless of what happens in the test execution.
|
||||
*/
|
||||
teardown(): void;
|
||||
|
||||
/**
|
||||
* Returns a promise that will be resolved with an array of
|
||||
* all matched HTTP requests.
|
||||
*/
|
||||
requestsMade(): webdriver.promise.Promise<Array<ReceivedRequest>>;
|
||||
|
||||
/**
|
||||
* Returns a promise that will be resolved with a true boolean
|
||||
* when all matched HTTP requests are cleared.
|
||||
*/
|
||||
clearRequests(): webdriver.promise.Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Module configuration to setup
|
||||
*/
|
||||
config: {
|
||||
/**
|
||||
* Mocks directory where mock files are located.
|
||||
* Default: process.cwd()
|
||||
*/
|
||||
rootDirectory?: string;
|
||||
|
||||
/**
|
||||
* Path to protractor configuration file.
|
||||
* Default: protractor.conf
|
||||
*/
|
||||
protractorConfig?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Matched request.
|
||||
*/
|
||||
interface ReceivedRequest {
|
||||
url: string;
|
||||
method: string;
|
||||
}
|
||||
|
||||
module requests {
|
||||
/**
|
||||
* Base request mock used for all mocks.
|
||||
*/
|
||||
interface BaseRequest<TResponse> {
|
||||
request: {
|
||||
method: string;
|
||||
path: string;
|
||||
};
|
||||
response: {
|
||||
status: number;
|
||||
data: TResponse;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* GET request mock.
|
||||
*/
|
||||
interface Get<TResponse> extends BaseRequest<TResponse> {
|
||||
request: {
|
||||
method: string;
|
||||
path: string;
|
||||
params?: Object;
|
||||
queryString?: Object;
|
||||
headers?: Object;
|
||||
interceptedRequest?: boolean;
|
||||
interceptedAnonymousRequest?: boolean;
|
||||
};
|
||||
response: {
|
||||
status: number;
|
||||
data: TResponse;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* POST request mock with payload.
|
||||
*/
|
||||
interface PostData<TResponse, TPayload> extends BaseRequest<TResponse> {
|
||||
request: {
|
||||
path: string;
|
||||
method: string;
|
||||
data: TPayload;
|
||||
};
|
||||
response: {
|
||||
status: number;
|
||||
data: TResponse;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* POST request mock.
|
||||
*/
|
||||
interface Post<TResponse> extends BaseRequest<TResponse> {
|
||||
request: {
|
||||
path: string;
|
||||
method: string;
|
||||
};
|
||||
response: {
|
||||
status: number;
|
||||
data: TResponse;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* HEAD request mock.
|
||||
*/
|
||||
interface Head<TResponse> extends BaseRequest<TResponse> {
|
||||
request: {
|
||||
path: string;
|
||||
method: string;
|
||||
};
|
||||
response: {
|
||||
status: number;
|
||||
data: TResponse;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP Delete request mock.
|
||||
*/
|
||||
interface Delete<TResponse> extends BaseRequest<TResponse> {
|
||||
request: {
|
||||
path: string;
|
||||
method: string;
|
||||
};
|
||||
response: {
|
||||
status: number;
|
||||
data: TResponse;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT request mock.
|
||||
*/
|
||||
interface Put<TResponse> extends BaseRequest<TResponse> {
|
||||
request: {
|
||||
path: string;
|
||||
method: string;
|
||||
};
|
||||
response: {
|
||||
status: number;
|
||||
data: TResponse;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* PATCH request mock.
|
||||
*/
|
||||
interface Patch<TResponse> extends BaseRequest<TResponse> {
|
||||
request: {
|
||||
path: string;
|
||||
method: string;
|
||||
};
|
||||
response: {
|
||||
status: number;
|
||||
data: TResponse;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* JSONP request mock.
|
||||
*/
|
||||
interface Jsonp<TResponse> extends BaseRequest<TResponse> {
|
||||
request: {
|
||||
path: string;
|
||||
method: string;
|
||||
};
|
||||
response: {
|
||||
status: number;
|
||||
data: TResponse;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare var mock: mock.ProtractorHttpMock;
|
||||
|
||||
declare module 'protractor-http-mock' {
|
||||
export = mock;
|
||||
}
|
||||
Reference in New Issue
Block a user