diff --git a/protractor-http-mock/protractor-http-mock-tests.ts b/protractor-http-mock/protractor-http-mock-tests.ts
index 6c39f1401a..e6620d015f 100644
--- a/protractor-http-mock/protractor-http-mock-tests.ts
+++ b/protractor-http-mock/protractor-http-mock-tests.ts
@@ -1,212 +1,242 @@
///
-function TestConfig() {
+function TestConfig() {
mock.config = {
- rootDirectory: 'root',
- protractorConfig: 'protractor.conf.js'
- };
+ rootDirectory: "root",
+ protractorConfig: "protractor.conf.js"
+ };
}
function TestCtorOverloads() {
- let noParam: mock.ProtractorHttpMock = mock();
+ let noParam: mock.ProtractorHttpMock = mock();
let emptyArray: mock.ProtractorHttpMock = mock([]);
- let mockFiles: mock.ProtractorHttpMock = mock(['mock1', 'mock2']);
- let skipDefaults: mock.ProtractorHttpMock = mock([], true);
+ let mockFiles: mock.ProtractorHttpMock = mock(["mock1", "mock2"]);
+ let skipDefaults: mock.ProtractorHttpMock = mock([], true);
- let del: mock.requests.Delete = {
- request: {
- path: 'path',
- method: 'DELETE'
- },
- response: {
- status: 400,
- data: 1
- }
- };
- let put: mock.requests.Put = {
- request: {
- path: 'path',
- method: 'PUT'
- },
- response: {
- status: 400,
- data: 1
- }
- };
- let mocks: mock.ProtractorHttpMock = mock([del, put]);
+ let del: mock.requests.Delete = {
+ request: {
+ path: "path",
+ method: "DELETE"
+ },
+ response: {
+ status: 400,
+ data: 1
+ }
+ };
+ let put: mock.requests.Put = {
+ request: {
+ path: "path",
+ method: "PUT"
+ },
+ response: {
+ status: 400,
+ data: 1
+ }
+ };
+ let mocks: mock.ProtractorHttpMock = mock([del, put]);
}
function TestTeardown() {
- mock.teardown();
+ mock.teardown();
}
function TestRequestsMade() {
- let values: Array;
- mock.requestsMade().then(v => values = v);
+ let values: Array;
+ mock.requestsMade().then(v => values = v);
}
function TestClearRequests() {
- let promiseValue: boolean;
- mock.clearRequests().then(value => {
- promiseValue = value;
- });
+ let promiseValue: boolean;
+ mock.clearRequests().then(value => {
+ promiseValue = value;
+ });
+}
+
+function TestDynamicAdd() {
+ let put: mock.requests.Put = {
+ request: {
+ path: "path",
+ method: "PUT"
+ },
+ response: {
+ status: 400,
+ data: 1
+ }
+ };
+ let resolved: boolean;
+ mock.add([put]).then(r => resolved = r);
+}
+
+function TestDyanmicRemove() {
+ let put: mock.requests.Put = {
+ request: {
+ path: "path",
+ method: "PUT"
+ },
+ response: {
+ status: 400,
+ data: 1
+ }
+ };
+ let resolved: boolean;
+ mock.remove([put]).then(r => resolved = r);
}
function TestGetRequestDefinitions() {
- let getMinium: mock.requests.Get = {
- request: {
- path: 'path',
- method: 'GET'
- },
- response: {
- data: 1,
- status: 500
- }
- };
+ let getMinium: mock.requests.Get = {
+ request: {
+ path: "path",
+ method: "GET"
+ },
+ response: {
+ data: 1,
+ status: 500
+ }
+ };
- let getParams: mock.requests.Get = {
- request: {
- path: 'path',
- method: 'GET',
- params: {
- param1: 'param1',
- param2: 2
- }
- },
- response: {
- data: 1,
- status: 500
- }
- };
+ let getParams: mock.requests.Get = {
+ request: {
+ path: "path",
+ method: "GET",
+ params: {
+ param1: "param1",
+ param2: 2
+ }
+ },
+ response: {
+ data: 1,
+ status: 500
+ }
+ };
- let post: mock.requests.Post = {
- request: {
- path: 'path',
- method: 'POST'
- },
- response: {
- data: 1,
- status: 500
- }
- };
+ let post: mock.requests.Post = {
+ request: {
+ path: "path",
+ method: "POST"
+ },
+ response: {
+ data: 1,
+ status: 500
+ }
+ };
- let getQueryString: mock.requests.Get = {
- request: {
- path: 'path',
- method: 'GET',
- queryString: {
- query1: 'query1',
- query2: 2
- }
- },
- response: {
- data: 1,
- status: 500
- }
- };
+ let getQueryString: mock.requests.Get = {
+ request: {
+ path: "path",
+ method: "GET",
+ queryString: {
+ query1: "query1",
+ query2: 2
+ }
+ },
+ response: {
+ data: 1,
+ status: 500
+ }
+ };
- let getHeaders: mock.requests.Get = {
- request: {
- path: 'path',
- method: 'GET',
- headers: {
- head1: 'head1',
- head2: 'head2'
- }
- },
- response: {
- data: 1,
- status: 500
- }
- };
+ let getHeaders: mock.requests.Get = {
+ request: {
+ path: "path",
+ method: "GET",
+ headers: {
+ head1: "head1",
+ head2: "head2"
+ }
+ },
+ response: {
+ data: 1,
+ status: 500
+ }
+ };
}
function TestPostRequestDefinitions() {
- let post: mock.requests.Post = {
- request: {
- path: 'path',
- method: 'POST'
- },
- response: {
- data: 1,
- status: 500
- }
- };
+ let post: mock.requests.Post = {
+ request: {
+ path: "path",
+ method: "POST"
+ },
+ response: {
+ data: 1,
+ status: 500
+ }
+ };
- let postData: mock.requests.PostData = {
- request: {
- path: 'path',
- method: 'POST',
- data: 'data'
- },
- response: {
- data: 1,
- status: 500
- }
- };
+ let postData: mock.requests.PostData = {
+ request: {
+ path: "path",
+ method: "POST",
+ data: "data"
+ },
+ response: {
+ data: 1,
+ status: 500
+ }
+ };
}
function TestHeadRequestDefinitions() {
- let head: mock.requests.Head = {
- request: {
- path: 'path',
- method: 'HEAD'
- },
- response: {
- status: 500,
- data: 1
- }
- };
+ let head: mock.requests.Head = {
+ request: {
+ path: "path",
+ method: "HEAD"
+ },
+ response: {
+ status: 500,
+ data: 1
+ }
+ };
}
function TestDeleteRequestDefinitions() {
- let del: mock.requests.Delete = {
- request: {
- path: 'path',
- method: 'DELETE'
- },
- response: {
- status: 500,
- data: 1
- }
- };
+ let del: mock.requests.Delete = {
+ request: {
+ path: "path",
+ method: "DELETE"
+ },
+ response: {
+ status: 500,
+ data: 1
+ }
+ };
}
function TestPutRequestDefinitions() {
- let put: mock.requests.Put = {
- request: {
- path: 'path',
- method: 'PUT'
- },
- response: {
- status: 500,
- data: 1
- }
- };
+ let put: mock.requests.Put = {
+ request: {
+ path: "path",
+ method: "PUT"
+ },
+ response: {
+ status: 500,
+ data: 1
+ }
+ };
}
function TestPatchRequestDefinitions() {
- let patch: mock.requests.Patch = {
- request: {
- path: 'path',
- method: 'PATCH'
- },
- response: {
- status: 500,
- data: 1
- }
- };
+ let patch: mock.requests.Patch = {
+ request: {
+ path: "path",
+ method: "PATCH"
+ },
+ response: {
+ status: 500,
+ data: 1
+ }
+ };
}
function TestJsonpRequestDefinitions() {
- let jsonp: mock.requests.Jsonp = {
- request: {
- path: 'path',
- method: 'JSONP'
- },
- response: {
- status: 500,
- data: 1
- }
- };
+ let jsonp: mock.requests.Jsonp = {
+ request: {
+ path: "path",
+ method: "JSONP"
+ },
+ response: {
+ status: 500,
+ data: 1
+ }
+ };
}
diff --git a/protractor-http-mock/protractor-http-mock.d.ts b/protractor-http-mock/protractor-http-mock.d.ts
index dcb2345d26..b953d8eb22 100644
--- a/protractor-http-mock/protractor-http-mock.d.ts
+++ b/protractor-http-mock/protractor-http-mock.d.ts
@@ -57,6 +57,24 @@ declare namespace mock {
*/
protractorConfig?: string;
};
+
+ /**
+ * Add mock dynamically.
+ * Returns a promise that will be resolved with a true boolean
+ * when mocks have been added.
+ *
+ * @param mocks An array of mock modules to load into the application.
+ */
+ add(mocks: Array>): webdriver.promise.Promise;
+
+ /**
+ * Remove mock dynamically.
+ * Returns a promise that will be resolved with a true boolean
+ * when mocks have been removed.
+ *
+ * @param mocks An array of mock modules to remove from the application.
+ */
+ remove(mocks: Array>): webdriver.promise.Promise;
}
/**
@@ -68,12 +86,17 @@ declare namespace mock {
}
namespace requests {
+ /**
+ * Request methods type
+ */
+ type Method = "GET" | "POST" | "DELETE" | "PUT" | "HEAD" | "PATCH" | "JSONP";
+
/**
* Base request mock used for all mocks.
*/
interface BaseRequest {
request: {
- method: string;
+ method: Method;
path: string;
};
response: {
@@ -87,7 +110,7 @@ declare namespace mock {
*/
interface Get extends BaseRequest {
request: {
- method: string;
+ method: Method;
path: string;
params?: Object;
queryString?: Object;
@@ -107,7 +130,7 @@ declare namespace mock {
interface PostData extends BaseRequest {
request: {
path: string;
- method: string;
+ method: Method;
data: TPayload;
};
response: {
@@ -122,7 +145,7 @@ declare namespace mock {
interface Post extends BaseRequest {
request: {
path: string;
- method: string;
+ method: Method;
};
response: {
status: number;
@@ -136,7 +159,7 @@ declare namespace mock {
interface Head extends BaseRequest {
request: {
path: string;
- method: string;
+ method: Method;
};
response: {
status: number;
@@ -150,7 +173,7 @@ declare namespace mock {
interface Delete extends BaseRequest {
request: {
path: string;
- method: string;
+ method: Method;
};
response: {
status: number;
@@ -164,7 +187,7 @@ declare namespace mock {
interface Put extends BaseRequest {
request: {
path: string;
- method: string;
+ method: Method;
};
response: {
status: number;
@@ -178,7 +201,7 @@ declare namespace mock {
interface Patch extends BaseRequest {
request: {
path: string;
- method: string;
+ method: Method;
};
response: {
status: number;
@@ -192,7 +215,7 @@ declare namespace mock {
interface Jsonp extends BaseRequest {
request: {
path: string;
- method: string;
+ method: Method;
};
response: {
status: number;
@@ -204,6 +227,6 @@ declare namespace mock {
declare var mock: mock.ProtractorHttpMock;
-declare module 'protractor-http-mock' {
+declare module "protractor-http-mock" {
export = mock;
}