File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ const res = await flickr.test.login()
87
87
console .log (res .body )
88
88
89
89
// new
90
- const body = await flickr (' flickr.test.login' )
90
+ const body = await flickr (' flickr.test.login' , {} )
91
91
console .log (body)
92
92
```
93
93
@@ -116,6 +116,7 @@ import * as assert from 'node:assert'
116
116
// mock transport returns the response you pass in the constructor
117
117
const transport = new MockTransport ({
118
118
stat: ' ok' ,
119
+ foo: ' bar'
119
120
})
120
121
121
122
// null auth does nothing
Original file line number Diff line number Diff line change 1
1
import { Transport } from "../types"
2
2
3
3
export class MockTransport implements Transport {
4
- private response : string
4
+ private responses : string [ ] = [ ]
5
5
6
- constructor ( response : any ) {
7
- this . response =
6
+ constructor ( response ?: string ) {
7
+ if ( response ) {
8
+ this . addMock ( response )
9
+ }
10
+ }
11
+
12
+ reset ( ) :void {
13
+ this . responses = [ ]
14
+ }
15
+
16
+ addMock ( response : string ) : void {
17
+ const stringResponse =
8
18
typeof response === "string" ? response : JSON . stringify ( response )
19
+ this . responses . push ( stringResponse )
9
20
}
10
21
11
22
async get ( ) : Promise < Response > {
12
- return new Response ( this . response )
23
+ return new Response ( this . responses . shift ( ) )
13
24
}
14
25
15
26
async post ( ) : Promise < Response > {
16
- return new Response ( this . response )
27
+ return new Response ( this . responses . shift ( ) )
17
28
}
18
29
}
You can’t perform that action at this time.
0 commit comments