-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.d.ts
73 lines (64 loc) · 2.13 KB
/
index.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
63
64
65
66
67
68
69
70
71
72
73
import Knex = require('knex');
import { EventEmitter } from 'events';
/**
* Attaches mocked client to knex instance
*
* @param knex initialized knex client
*/
export function mock(knex: Knex): void;
/**
* Detaches mocked client from knex instance
*
* @param knex initialized knex client
*/
export function unmock(knex: Knex): void;
/**
* Returns query Tracker instance
*/
export function getTracker(): Tracker;
/**
* The tracker enables you to catch and respond to queries that occur during testing, see Test for more examples.
*/
export interface Tracker extends EventEmitter {
/**
* Enables query tracking mock on mocked knex client
*/
install(): void;
/**
* Disables query tracking mock on mocked knex client. Also resets 'step' counter.
*/
uninstall(): void;
/**
* Add event listener for 'query' event. It gets esecuted for each query that should end up in database.
* Instead of this callback gets executed and its up to you to assert queries and mock database responses.
*
* @param event
* @param callback A function that gets executed on 'query' event.
*/
on(event: 'query', callback: (query: QueryDetails, step: number) => void): this;
}
/**
* The object containing query details that is being sent to knex database dialect on query execution.
* Object properties signature matches with knex toSQL() output with additional method returns(values).
*/
export interface QueryDetails extends Knex.Sql {
/**
* Function that needs to be called to mock database query result for knex.
*
* @param error The Error, string or instance of Error, which represents why the result was rejected
*/
reject(error: Error | string): void;
/**
* Function that needs to be called to mock database query result for knex.
*
* @param values An array of mock data to be returned by database. For Bookshelf this is mostly array of objects. Knex could return any type of data.
* @param options
*/
response(values: any[], options?: QueryDetailsResponseOption): void;
}
export interface QueryDetailsResponseOption {
/**
* Is this a stream response, defaults to false
*/
stream: boolean;
}