|
1 | 1 | /** |
2 | | - * This request wrapper controls what will be returned by one url / http verb |
3 | | - * Normally when you set up pretender, you give it one function to handle one url / verb. |
4 | | - * |
5 | | - * So, for example, you would: |
6 | | - * |
7 | | - * ``` |
8 | | - * pretender.get('/users', myfunction ) |
9 | | - * ``` |
10 | | - * |
11 | | - * to mock a [GET /users] call |
12 | | - * |
13 | | - * This wrapper allows that GET /users call to be handled my many functions |
14 | | - * instead of just one, since this request handler hold the ability to take |
15 | | - * a list of hanlders. |
16 | | - * |
17 | | - * That way you can setup a few mocks like |
18 | | - * |
19 | | - * ``` |
20 | | - * mockFindAll('user') |
21 | | - * mockQuery('user', {name: 'Dude'}) |
22 | | - * ``` |
23 | | - * |
24 | | - * and both of these hanlders will reside in the list for the wrapper that |
25 | | - * belongs to [GET /users] |
| 2 | + * This request wrapper controls what will be returned by one url / http verb. |
| 3 | + * Holds a list of handlers for a given url/verb pair so multiple mocks (e.g. |
| 4 | + * mockFindAll and mockQuery) can share the same route. |
26 | 5 | */ |
27 | 6 | export default class RequestWrapper { |
28 | 7 | constructor() { |
29 | 8 | this.index = 0; |
30 | 9 | this.handlers = []; |
31 | | - return this.generateRequestHandler(); |
32 | | - } |
33 | | - |
34 | | - /** |
35 | | - * Generating a function that we can hand off to pretender that |
36 | | - * will handle the request. |
37 | | - * |
38 | | - * Before passing back that function, add some other functions |
39 | | - * to control the handlers array |
40 | | - * |
41 | | - * @returns {function(this:T)} |
42 | | - */ |
43 | | - generateRequestHandler() { |
44 | | - const requestHandler = this.handleRequest.bind(this); |
45 | | - requestHandler.getHandlers = this.getHandlers.bind(this); |
46 | | - requestHandler.addHandler = this.addHandler.bind(this); |
47 | | - requestHandler.removeHandler = this.removeHandler.bind(this); |
48 | | - return requestHandler; |
49 | 10 | } |
50 | 11 |
|
51 | 12 | /** |
|
0 commit comments