index.d.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. declare function mm(target: any, key: string, prop: any): void;
  2. declare namespace mm {
  3. // export MockMate type for egg-mock;
  4. type MockMate = typeof mm;
  5. type Request = (
  6. url: string | RegExp | { url: string; host: string },
  7. data: any,
  8. headers?: object,
  9. delay?: number
  10. ) => MockMate;
  11. type RequestError = (
  12. url: string | RegExp | { url: string; host: string },
  13. reqError: string | Error,
  14. resError: string | Error,
  15. delay?: number
  16. ) => MockMate;
  17. /**
  18. * Mock async function error.
  19. */
  20. function error(mod: any, method: string, error?: string | Error, props?: object, timeout?: number): MockMate;
  21. /**
  22. * Mock async function error once.
  23. */
  24. function errorOnce(mod: any, method: string, error?: string | Error, props?: object, timeout?: number): MockMate;
  25. /**
  26. * mock return callback(null, data).
  27. */
  28. function data(mod: any, method: string, data: any, timeout?: number): MockMate;
  29. /**
  30. * mock return callback(null, null).
  31. */
  32. function empty(mod: any, method: string, timeout?: number): MockMate;
  33. /**
  34. * mock return callback(null, data1, data2).
  35. */
  36. function datas(mod: any, method: string, datas: any, timeout?: number): MockMate;
  37. /**
  38. * mock function sync throw error
  39. */
  40. function syncError(mod: any, method: string, error?: string | Error, props?: object): void;
  41. /**
  42. * mock function sync return data
  43. */
  44. function syncData(mod: any, method: string, data?: any): void;
  45. /**
  46. * mock function sync return nothing
  47. */
  48. function syncEmpty(mod: any, method: string): void;
  49. /**
  50. * remove all mock effects.
  51. */
  52. function restore(): MockMate;
  53. const http: {
  54. request: Request;
  55. requestError: RequestError;
  56. };
  57. const https: {
  58. request: Request;
  59. requestError: RequestError;
  60. };
  61. }
  62. export = mm;