🤖 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:
Jie
2022-09-25 00:54:49 +08:00
committed by GitHub
parent 4d8ca9d3d9
commit d5c1940b75
2 changed files with 17 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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}