@@ -5,34 +5,40 @@ import FetchMock, { Mock } from '../';
55const fetch = new FetchMock ( require ( '../__mocks__' ) ) . fetch ;
66describe ( 'test fetch mock' , ( ) => {
77 it ( 'fetch /api/users data' , async ( ) => {
8- const { status, data } = await fetch ( '/api/users' ) ;
8+ const response = await fetch ( '/api/users' ) ;
9+ const { status } = response ;
910 expect ( status ) . to . be . eql ( 200 ) ;
11+ const data = await response . json ( ) ;
1012 expect ( data ) . not . to . be ( undefined ) ;
1113 expect ( data ) . not . to . be . empty ( ) ;
1214 expect ( data ) . to . be . an ( 'array' ) ;
1315 expect ( data ) . to . have . length ( 2 ) ;
1416 } ) ;
1517
1618 it ( 'fetch /api/users?a=b' , async ( ) => {
17- const { status, data } = await fetch ( '/api/users' ) ;
19+ const response = await fetch ( '/api/users' ) ;
20+ const { status } = response ;
1821 expect ( status ) . to . be . eql ( 200 ) ;
22+ const data = await response . json ( ) ;
1923 expect ( data ) . not . to . be ( undefined ) ;
2024 expect ( data ) . not . to . be . empty ( ) ;
2125 expect ( data ) . to . be . an ( 'array' ) ;
2226 expect ( data ) . to . have . length ( 2 ) ;
2327 } ) ;
2428
2529 it ( 'fetch /api/users with url parameters' , async ( ) => {
26- const { status, data } = await fetch ( '/api/users?name=John' ) ;
30+ const response = await fetch ( '/api/users?name=John' ) ;
31+ const { status } = response ;
2732 expect ( status ) . to . be . eql ( 200 ) ;
33+ const data = await response . json ( ) ;
2834 expect ( data ) . not . to . be ( undefined ) ;
2935 expect ( data ) . not . to . be . empty ( ) ;
3036 expect ( data ) . to . be . an ( 'array' ) ;
3137 expect ( data ) . to . have . length ( 1 ) ;
3238 } ) ;
3339
3440 it ( 'fetch /api/users with post parameters' , async ( ) => {
35- const { status , data } = await fetch ( '/api/users' , {
41+ const response = await fetch ( '/api/users' , {
3642 method : 'GET' ,
3743 headers : {
3844 'Content-Type' : 'application/json' ,
@@ -41,33 +47,41 @@ describe('test fetch mock', () => {
4147 name : 'John' ,
4248 } ) ,
4349 } ) ;
50+ const { status } = response ;
4451 expect ( status ) . to . be . eql ( 200 ) ;
52+ const data = await response . json ( ) ;
4553 expect ( data ) . not . to . be ( undefined ) ;
4654 expect ( data ) . not . to . be . empty ( ) ;
4755 expect ( data ) . to . be . an ( 'array' ) ;
4856 expect ( data ) . to . have . length ( 1 ) ;
4957 } ) ;
5058
5159 it ( 'fetch /api/users/{userId}' , async ( ) => {
52- const { status, data } = await fetch ( '/api/users/123' ) ;
60+ const response = await fetch ( '/api/users/123' ) ;
61+ const { status } = response ;
5362 expect ( status ) . to . be . eql ( 200 ) ;
63+ const data = await response . json ( ) ;
5464 expect ( data ) . not . to . be ( undefined ) ;
5565 expect ( data ) . not . to . be . empty ( ) ;
5666 expect ( data ) . to . be . property ( 'userId' , '123' ) ;
5767 } ) ;
5868
5969 it ( 'fetch /api/users/mockjs with mockjs' , async ( ) => {
60- const { status, data } = await fetch ( '/api/users/mockjs' ) ;
70+ const response = await fetch ( '/api/users/mockjs' ) ;
71+ const { status } = response ;
6172 expect ( status ) . to . be . eql ( 200 ) ;
73+ const data = await response . json ( ) ;
6274 expect ( data ) . not . to . be ( undefined ) ;
6375 expect ( data ) . not . to . be . empty ( ) ;
6476 expect ( data ) . to . be . an ( 'array' ) ;
6577 expect ( data ) . to . have . length ( 2 ) ;
6678 } ) ;
6779
6880 it ( 'fetch /api/users/mockjs with mockjs' , async ( ) => {
69- const { status, data } = await fetch ( '/api/users/mockjs' ) ;
81+ const response = await fetch ( '/api/users/mockjs' ) ;
82+ const { status } = response ;
7083 expect ( status ) . to . be . eql ( 200 ) ;
84+ const data = await response . json ( ) ;
7185 expect ( data ) . not . to . be ( undefined ) ;
7286 expect ( data ) . not . to . be . empty ( ) ;
7387 expect ( data ) . to . be . an ( 'array' ) ;
@@ -88,7 +102,7 @@ describe('test fetch mock', () => {
88102 } ) ;
89103
90104 it ( 'put /api/users/123' , async ( ) => {
91- const { status , data } = await fetch ( '/api/users/123' , {
105+ const response = await fetch ( '/api/users/123' , {
92106 method : 'PUT' ,
93107 headers : {
94108 'Content-Type' : 'application/json' ,
@@ -97,7 +111,9 @@ describe('test fetch mock', () => {
97111 name : 'John2' ,
98112 } ) ,
99113 } ) ;
114+ const { status } = response ;
100115 expect ( status ) . to . be . eql ( 204 ) ;
116+ const data = await response . json ( ) ;
101117 expect ( data ) . not . to . be ( undefined ) ;
102118 expect ( data ) . not . to . be . empty ( ) ;
103119 expect ( data ) . to . be . an ( 'object' ) ;
0 commit comments