forked from alonronin/mockingoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.d.ts
62 lines (61 loc) · 1.87 KB
/
types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as mongoose from 'mongoose';
declare const ops: [
'find',
'findOne',
'count',
'countDocuments',
'estimatedDocumentCount',
'distinct',
'findOneAndUpdate',
'findOneAndDelete',
'findOneAndRemove',
'findOneAndReplace',
'remove',
'update',
'deleteOne',
'deleteMany',
'save',
'aggregate'
];
declare type Ops = typeof ops[number];
declare type ReturnFunction = (param: mongoose.Query<any> | mongoose.Aggregate<any>) => {};
declare type ExpectedReturnType = string | number | boolean | symbol | object | {} | void | null | undefined;
interface Mock {
/**
* Specify an expected result for a specific mongoose function. This can be a primitive value or a function.
* If used with a function, you will have access to the Query or Aggregate mongoose class.
* @param expected Primitive value or function that returns the mocked value
* @param op The operation to mock
*/
toReturn(expected: ExpectedReturnType | ReturnFunction, op?: Ops): this;
/**
* Reset all mocks
* @param op Optional parameter to reset, if not specified, resets everything
*/
reset(op?: Ops): this;
/**
* Returns an object of mocks for this model. Only serializable if all mock results are primitives, not functions.
*/
toJSON(): any;
}
interface Target {
__mocks: any;
/**
* Resets all mocks.
*/
resetAll(): void;
/**
* Returns an object of mocks for all models. Only serializable if all mock results are primitives, not functions.
*/
toJSON(): any;
}
declare type Proxy = Target & {
[index: string]: Mock;
} & typeof mockModel;
declare const mockingoose: Proxy;
/**
* Returns a helper with which you can set up mocks for a particular Model
* @param {string | mongoose.Model} model either a string model name, or a mongoose.Model instance
*/
declare const mockModel: (model: string | mongoose.Model<any, {}>) => Mock;
export default mockingoose;