11/* eslint-disable import/first */
2- /* eslint-disable import/newline-after-import */
32/* globals describe,test,expect,jest,afterEach,beforeAll */
4- import '@babel/runtime/regenerator' ;
5- jest . mock ( 'cross-fetch' ) ;
63import fetch from 'cross-fetch' ;
7- import HttpTransport from './HttpTransport' ;
4+
5+ jest . mock ( 'cross-fetch' ) ;
6+
7+ import HttpTransport from '../src/HttpTransport' ;
8+
9+ const mockedFetch = fetch as jest . MockedFunction < typeof fetch > ;
810
911describe ( 'HttpTransport' , ( ) => {
1012 const apiUrl = 'http://localhost:3000/cubejs-api/v1' ;
@@ -31,11 +33,11 @@ describe('HttpTransport', () => {
3133 const largeQueryJson = `{"query":{"measures":["Orders.count"],"dimensions":["Users.country"],"filters":[{"member":"Users.id","operator":"equals","values":${ JSON . stringify ( ids ) } }]}}` ;
3234
3335 beforeAll ( ( ) => {
34- fetch . mockReturnValue ( Promise . resolve ( { ok : true } ) ) ;
36+ mockedFetch . mockReturnValue ( Promise . resolve ( { ok : true } as Response ) ) ;
3537 } ) ;
3638
3739 afterEach ( ( ) => {
38- fetch . mockClear ( ) ;
40+ mockedFetch . mockClear ( ) ;
3941 } ) ;
4042
4143 test ( 'it serializes the query object and sends it in the query string' , async ( ) => {
@@ -44,7 +46,7 @@ describe('HttpTransport', () => {
4446 apiUrl,
4547 } ) ;
4648 const req = transport . request ( 'load' , { query } ) ;
47- await req . subscribe ( ( ) => { } ) ;
49+ await req . subscribe ( ( ) => { console . log ( 'subscribe cb' ) ; } ) ;
4850 expect ( fetch ) . toHaveBeenCalledTimes ( 1 ) ;
4951 expect ( fetch ) . toHaveBeenCalledWith ( `${ apiUrl } /load?query=${ queryUrlEncoded } ` , {
5052 method : 'GET' ,
@@ -66,7 +68,7 @@ describe('HttpTransport', () => {
6668 }
6769 } ) ;
6870 const req = transport . request ( 'meta' , { extraParams } ) ;
69- await req . subscribe ( ( ) => { } ) ;
71+ await req . subscribe ( ( ) => { console . log ( 'subscribe cb' ) ; } ) ;
7072 expect ( fetch ) . toHaveBeenCalledTimes ( 1 ) ;
7173 expect ( fetch ) . toHaveBeenCalledWith ( `${ apiUrl } /meta?extraParams=${ serializedExtraParams } ` , {
7274 method : 'GET' ,
@@ -85,7 +87,7 @@ describe('HttpTransport', () => {
8587 method : 'POST'
8688 } ) ;
8789 const req = transport . request ( 'load' , { query } ) ;
88- await req . subscribe ( ( ) => { } ) ;
90+ await req . subscribe ( ( ) => { console . log ( 'subscribe cb' ) ; } ) ;
8991 expect ( fetch ) . toHaveBeenCalledTimes ( 1 ) ;
9092 expect ( fetch ) . toHaveBeenCalledWith ( `${ apiUrl } /load` , {
9193 method : 'POST' ,
@@ -103,7 +105,7 @@ describe('HttpTransport', () => {
103105 apiUrl
104106 } ) ;
105107 const req = transport . request ( 'load' , { query : LargeQuery } ) ;
106- await req . subscribe ( ( ) => { } ) ;
108+ await req . subscribe ( ( ) => { console . log ( 'subscribe cb' ) ; } ) ;
107109 expect ( fetch ) . toHaveBeenCalledTimes ( 1 ) ;
108110 expect ( fetch ) . toHaveBeenCalledWith ( `${ apiUrl } /load` , {
109111 method : 'POST' ,
0 commit comments