File tree Expand file tree Collapse file tree 3 files changed +33
-52
lines changed Expand file tree Collapse file tree 3 files changed +33
-52
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11
22export default {
3- '/api/users' : async ( ) => {
3+ '/api/users' : async ( options ) => {
4+ const all = [
5+ {
6+ name : 'John' ,
7+ age : 15 ,
8+ } ,
9+ {
10+ name : 'Lily' ,
11+ age : 16 ,
12+ }
13+ ] ;
14+ let filtered ;
15+ if ( 'undefined' !== typeof options ) {
16+ filtered = all . filter ( item => {
17+ let result = true ;
18+ const keys = Object . keys ( options ) ;
19+ keys . forEach ( key => {
20+ const option = options [ key ] ;
21+
22+ if ( item [ key ] && item [ key ] !== option ) {
23+ result = false ;
24+ }
25+ } ) ;
26+
27+ return result ;
28+ } ) ;
29+ } else {
30+ filtered = all ;
31+ }
432 return {
5- data : [
6- {
7- name : 'John' ,
8- age : 15 ,
9- } ,
10- {
11- name : 'Lily' ,
12- age : 16 ,
13- }
14- ]
33+ data : filtered ,
1534 }
1635 }
1736}
Original file line number Diff line number Diff line change @@ -13,12 +13,12 @@ describe('test fetch mock', () => {
1313 } ) ;
1414
1515 it ( 'fetch /api/users with parameters' , async ( ) => {
16- const { data } = await fetch ( '/api/users' . {
17-
16+ const { data } = await fetch ( '/api/users' , {
17+ name : 'John' ,
1818 } ) ;
1919 expect ( data ) . not . to . be ( undefined ) ;
2020 expect ( data ) . not . to . be . empty ( ) ;
2121 expect ( data ) . to . be . an ( 'array' ) ;
22- expect ( data ) . to . have . length ( 2 ) ;
22+ expect ( data ) . to . have . length ( 1 ) ;
2323 } ) ;
2424} ) ;
You can’t perform that action at this time.
0 commit comments