mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
🤖 Merge PR #62397 feat: add mockjs declaration by @DimplesY
* feat: add mockjs declaration * fix: add mockjs declaration * fix: change function declaration * fix: update declaration * fix: update test case * fix: update declaration
This commit is contained in:
12
types/mockjs/index.d.ts
vendored
12
types/mockjs/index.d.ts
vendored
@@ -20,12 +20,20 @@ declare namespace mockjs {
|
||||
version: number;
|
||||
}
|
||||
|
||||
interface MockjsRequestOptions {
|
||||
url: string;
|
||||
type: string;
|
||||
body: any;
|
||||
}
|
||||
|
||||
type templateOrFn = ((options: MockjsRequestOptions) => any) | object;
|
||||
|
||||
// Mockjs.mock()
|
||||
// see https://github.com/nuysoft/Mock/wiki/Mock.mock()
|
||||
interface MockjsMock {
|
||||
(rurl: S | RegExp, rtype: S, template: any): Mockjs;
|
||||
(rurl: S | RegExp, rtype: S, template: templateOrFn): Mockjs;
|
||||
|
||||
(rurl: S | RegExp, template: any): Mockjs;
|
||||
(rurl: S | RegExp, template: templateOrFn): Mockjs;
|
||||
|
||||
(template: any): any;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,13 @@ Mock.mock('/test', 'get', {
|
||||
name: 'mockjs',
|
||||
}).mock('/login', 'post', {
|
||||
status: 0,
|
||||
}).mock('/test', 'get', (config) => {
|
||||
console.log(config.url);
|
||||
console.log(config.type);
|
||||
console.log(config.body);
|
||||
return {
|
||||
name: 'mockjs',
|
||||
};
|
||||
});
|
||||
// When request '/test' will response {name: 'mockjs'}
|
||||
// When request '/login' will response {status: 0}
|
||||
|
||||
Reference in New Issue
Block a user