-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consistent formatting with prettier / editorconfig
- Loading branch information
1 parent
76f5ea3
commit c90d98c
Showing
10 changed files
with
704 additions
and
653 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_size = 4 | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
.awcache | ||
dist | ||
dist | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 4, | ||
"semi": true, | ||
"singleQuote": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import MockAxios from "./mock-axios"; | ||
export default MockAxios; | ||
import MockAxios from "./mock-axios"; | ||
export default MockAxios; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,109 @@ | ||
import SyncPromise from "jest-mock-promise"; | ||
|
||
export interface HttpResponse { | ||
data: any; | ||
status?: number; | ||
statusText?: string; | ||
headers?: object; | ||
config?: object; | ||
} | ||
|
||
export type AnyFunction = (...args: any[]) => any; | ||
|
||
// spy is a function which extends an object (it has static methods and properties) | ||
export type SpyFn = AnyFunction & { mockClear: AnyFunction }; | ||
|
||
export type AxiosFn = (...args: any[]) => SpyFn; | ||
|
||
interface Interceptors { | ||
request: { | ||
use: SpyFn, | ||
}; | ||
response: { | ||
use: SpyFn, | ||
}; | ||
} | ||
|
||
interface AxiosDefaults { | ||
headers: any; | ||
} | ||
|
||
export interface AxiosAPI { | ||
// mocking Axios methods | ||
get: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
post: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
put: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
patch: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
delete: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
head: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
options: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
request: jest.Mock<SyncPromise, [any?]>; | ||
all: SpyFn; | ||
create: jest.Mock<AxiosMockType, []>; | ||
interceptors: Interceptors; | ||
defaults: AxiosDefaults; | ||
} | ||
|
||
export interface AxiosMockAPI { | ||
/** | ||
* Simulate a server response, (optionally) with the given data | ||
* @param response (optional) response returned by the server | ||
* @param queueItem (optional) request promise for which response should be resolved | ||
* @param silentMode (optional) specifies whether the call should throw an error or | ||
* only fail quietly if no matching request is found. | ||
*/ | ||
mockResponse: ((response?: HttpResponse, queueItem?: SyncPromise|AxiosMockQueueItem, silentMode?: boolean) => void); | ||
/** | ||
* Simulate an error in server request | ||
* @param error (optional) error object | ||
* @param queueItem (optional) request promise for which response should be resolved | ||
* @param silentMode (optional) specifies whether the call should throw an error or | ||
* only fail quietly if no matching request is found. | ||
*/ | ||
mockError?: (error?: any, queueItem?: SyncPromise|AxiosMockQueueItem, silentMode?: boolean) => void; | ||
/** | ||
* Returns promise of the most recent request | ||
*/ | ||
lastPromiseGet?: () => SyncPromise; | ||
/** | ||
* Removes the give promise from the queue | ||
* @param promise | ||
*/ | ||
|
||
popPromise?: (promise?: SyncPromise) => SyncPromise; | ||
/** | ||
* Returns promise of the most recent request | ||
*/ | ||
lastReqGet?: () => AxiosMockQueueItem; | ||
/** | ||
* Removes the give request from the queue | ||
* @param promise | ||
*/ | ||
popRequest?: (promise?: AxiosMockQueueItem) => AxiosMockQueueItem; | ||
|
||
/** | ||
* Clears all of the queued requests | ||
*/ | ||
reset: () => void; | ||
} | ||
|
||
export interface AxiosMockQueueItem { | ||
promise: SyncPromise; | ||
url: string; | ||
data?: any; | ||
config?: any; | ||
} | ||
|
||
/** | ||
* Axios object can be called like a function, | ||
* that's why we're defining it as a spy | ||
*/ | ||
export type AxiosMockType = AxiosFn & AxiosAPI & AxiosMockAPI; | ||
import SyncPromise from "jest-mock-promise"; | ||
|
||
export interface HttpResponse { | ||
data: any; | ||
status?: number; | ||
statusText?: string; | ||
headers?: object; | ||
config?: object; | ||
} | ||
|
||
export type AnyFunction = (...args: any[]) => any; | ||
|
||
// spy is a function which extends an object (it has static methods and properties) | ||
export type SpyFn = AnyFunction & { mockClear: AnyFunction }; | ||
|
||
export type AxiosFn = (...args: any[]) => SpyFn; | ||
|
||
interface Interceptors { | ||
request: { | ||
use: SpyFn; | ||
}; | ||
response: { | ||
use: SpyFn; | ||
}; | ||
} | ||
|
||
interface AxiosDefaults { | ||
headers: any; | ||
} | ||
|
||
export interface AxiosAPI { | ||
// mocking Axios methods | ||
get: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
post: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
put: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
patch: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
delete: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
head: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
options: jest.Mock<SyncPromise, [string?, any?, any?]>; | ||
request: jest.Mock<SyncPromise, [any?]>; | ||
all: SpyFn; | ||
create: jest.Mock<AxiosMockType, []>; | ||
interceptors: Interceptors; | ||
defaults: AxiosDefaults; | ||
} | ||
|
||
export interface AxiosMockAPI { | ||
/** | ||
* Simulate a server response, (optionally) with the given data | ||
* @param response (optional) response returned by the server | ||
* @param queueItem (optional) request promise for which response should be resolved | ||
* @param silentMode (optional) specifies whether the call should throw an error or | ||
* only fail quietly if no matching request is found. | ||
*/ | ||
mockResponse: ( | ||
response?: HttpResponse, | ||
queueItem?: SyncPromise | AxiosMockQueueItem, | ||
silentMode?: boolean, | ||
) => void; | ||
/** | ||
* Simulate an error in server request | ||
* @param error (optional) error object | ||
* @param queueItem (optional) request promise for which response should be resolved | ||
* @param silentMode (optional) specifies whether the call should throw an error or | ||
* only fail quietly if no matching request is found. | ||
*/ | ||
mockError?: ( | ||
error?: any, | ||
queueItem?: SyncPromise | AxiosMockQueueItem, | ||
silentMode?: boolean, | ||
) => void; | ||
/** | ||
* Returns promise of the most recent request | ||
*/ | ||
lastPromiseGet?: () => SyncPromise; | ||
/** | ||
* Removes the give promise from the queue | ||
* @param promise | ||
*/ | ||
|
||
popPromise?: (promise?: SyncPromise) => SyncPromise; | ||
/** | ||
* Returns promise of the most recent request | ||
*/ | ||
lastReqGet?: () => AxiosMockQueueItem; | ||
/** | ||
* Removes the give request from the queue | ||
* @param promise | ||
*/ | ||
popRequest?: (promise?: AxiosMockQueueItem) => AxiosMockQueueItem; | ||
|
||
/** | ||
* Clears all of the queued requests | ||
*/ | ||
reset: () => void; | ||
} | ||
|
||
export interface AxiosMockQueueItem { | ||
promise: SyncPromise; | ||
url: string; | ||
data?: any; | ||
config?: any; | ||
} | ||
|
||
/** | ||
* Axios object can be called like a function, | ||
* that's why we're defining it as a spy | ||
*/ | ||
export type AxiosMockType = AxiosFn & AxiosAPI & AxiosMockAPI; |
Oops, something went wrong.