Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Jest dependency #99

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions lib/mock-axios-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {jest} from '@jest/globals';
import { SynchronousPromise, UnresolvedSynchronousPromise } from "synchronous-promise";
import { jest } from "@jest/globals";
import {
SynchronousPromise,
UnresolvedSynchronousPromise,
} from "synchronous-promise";

export interface HttpResponse {
data: any;
Expand All @@ -10,7 +13,12 @@ export interface HttpResponse {
}

interface Interceptor {
use: jest.Mock<(onFulfilled?: (value: any) => any | Promise<any>, onRejected?: (error: any) => any) => number>;
use: jest.Mock<
(
onFulfilled?: (value: any) => any | Promise<any>,
onRejected?: (error: any) => any
) => number
>;
eject: jest.Mock<(index: number) => void>;
clear: jest.Mock<() => void>;
}
Expand All @@ -31,8 +39,15 @@ interface AxiosDefaults {
headers: any;
}

type MockUnresolvedPromise = (url?: string, options?: any) => UnresolvedSynchronousPromise<any>;
type MockUnresolvedPromiseBody = (url?: string, body?: any, options?: any) => UnresolvedSynchronousPromise<any>;
type MockUnresolvedPromise = (
url?: string,
options?: any
) => UnresolvedSynchronousPromise<any>;
type MockUnresolvedPromiseBody = (
url?: string,
body?: any,
options?: any
) => UnresolvedSynchronousPromise<any>;

export interface AxiosAPI {
// mocking Axios methods
Expand Down Expand Up @@ -82,7 +97,7 @@ export interface AxiosMockAPI {
mockResponse: (
response?: HttpResponse,
queueItem?: Promise<any> | AxiosMockQueueItem,
silentMode?: boolean,
silentMode?: boolean
) => void;

/**
Expand All @@ -96,7 +111,7 @@ export interface AxiosMockAPI {
mockResponseFor: (
criteria: string | AxiosMockRequestCriteria,
response?: HttpResponse,
silentMode?: boolean,
silentMode?: boolean
) => void;

/**
Expand All @@ -109,7 +124,7 @@ export interface AxiosMockAPI {
mockError: (
error?: any,
queueItem?: Promise<any> | AxiosMockQueueItem,
silentMode?: boolean,
silentMode?: boolean
) => void;

/**
Expand All @@ -122,7 +137,9 @@ export interface AxiosMockAPI {
* @param promise
*/

popPromise: (promise?: UnresolvedSynchronousPromise<any>) => UnresolvedSynchronousPromise<any>;
popPromise: (
promise?: UnresolvedSynchronousPromise<any>
) => UnresolvedSynchronousPromise<any>;

/**
* Returns request item of the most recent request
Expand Down Expand Up @@ -173,7 +190,9 @@ export interface AxiosMockAPI {
* key_x: The key of the request to be found
* RegExp_x: The RegExp to be tested against that key
*/
getReqByRegex: (opts: {[key in keyof AxiosMockQueueItem]+?: RegExp}) => AxiosMockQueueItem;
getReqByRegex: (opts: {
[key in keyof AxiosMockQueueItem]+?: RegExp;
}) => AxiosMockQueueItem;

/**
* Removes the give request from the queue
Expand All @@ -194,7 +213,7 @@ export interface AxiosMockAPI {
/**
* Set a request handler that gets invoked every time a new request comes in
* The handler is invoked with the new request item
*
*
* @param handler the function to invoke with the new request item every time a new request comes in
*/
useRequestHandler: (handler: RequestHandler) => void;
Expand Down Expand Up @@ -222,4 +241,6 @@ export interface AxiosMockRequestCriteria {
* Axios object can be called like a function,
* that's why we're defining it as a spy
*/
export type AxiosMockType = AxiosAPI & AxiosMockAPI & jest.Mock<(options?: any) => any>;
export type AxiosMockType = AxiosAPI &
AxiosMockAPI &
jest.Mock<(options?: any) => any>;
Loading