@@ -15,7 +15,7 @@ import { createClient } from 'graphql-ws';
15
15
16
16
import { SubscriptionClient } from 'subscriptions-transport-ws' ;
17
17
18
- const exampleWithSubscription = /* GraphQL */ parse ( `
18
+ const exampleWithSubscription = parse ( /* GraphQL */ `
19
19
subscription Example {
20
20
example
21
21
}
@@ -47,9 +47,9 @@ describe('createWebsocketsFetcherFromUrl', () => {
47
47
jest . resetAllMocks ( ) ;
48
48
} ) ;
49
49
50
- it ( 'creates a websockets client using provided url' , ( ) => {
50
+ it ( 'creates a websockets client using provided url' , async ( ) => {
51
51
createClient . mockReturnValue ( true ) ;
52
- createWebsocketsFetcherFromUrl ( 'wss://example.com' ) ;
52
+ await createWebsocketsFetcherFromUrl ( 'wss://example.com' ) ;
53
53
// @ts -ignore
54
54
expect ( createClient . mock . calls [ 0 ] [ 0 ] ) . toEqual ( { url : 'wss://example.com' } ) ;
55
55
} ) ;
@@ -66,39 +66,41 @@ describe('getWsFetcher', () => {
66
66
afterEach ( ( ) => {
67
67
jest . resetAllMocks ( ) ;
68
68
} ) ;
69
- it ( 'provides an observable wsClient when custom wsClient option is provided' , ( ) => {
69
+ it ( 'provides an observable wsClient when custom wsClient option is provided' , async ( ) => {
70
70
createClient . mockReturnValue ( true ) ;
71
- getWsFetcher ( { url : '' , wsClient : true } ) ;
71
+ await getWsFetcher ( { url : '' , wsClient : true } ) ;
72
72
// @ts -ignore
73
73
expect ( createClient . mock . calls ) . toHaveLength ( 0 ) ;
74
74
} ) ;
75
- it ( 'creates a subscriptions-transports-ws observable when custom legacyClient option is provided' , ( ) => {
75
+ it ( 'creates a subscriptions-transports-ws observable when custom legacyClient option is provided' , async ( ) => {
76
76
createClient . mockReturnValue ( true ) ;
77
- getWsFetcher ( { url : '' , legacyClient : true } ) ;
77
+ await getWsFetcher ( { url : '' , legacyClient : true } ) ;
78
78
// @ts -ignore
79
79
expect ( createClient . mock . calls ) . toHaveLength ( 0 ) ;
80
80
expect ( SubscriptionClient . mock . calls ) . toHaveLength ( 0 ) ;
81
81
} ) ;
82
82
83
- it ( 'if subscriptionsUrl is provided, create a client on the fly' , ( ) => {
83
+ it ( 'if subscriptionsUrl is provided, create a client on the fly' , async ( ) => {
84
84
createClient . mockReturnValue ( true ) ;
85
- getWsFetcher ( { url : '' , subscriptionUrl : 'wss://example' } ) ;
85
+ await getWsFetcher ( { url : '' , subscriptionUrl : 'wss://example' } ) ;
86
86
expect ( createClient . mock . calls [ 0 ] ) . toEqual ( [
87
87
{ connectionParams : { } , url : 'wss://example' } ,
88
88
] ) ;
89
89
expect ( SubscriptionClient . mock . calls ) . toHaveLength ( 0 ) ;
90
90
} ) ;
91
91
} ) ;
92
92
93
- describe ( 'missing graphql-ws dependency' , ( ) => {
94
- it ( 'should throw a nice error' , ( ) => {
93
+ describe ( 'missing ` graphql-ws` dependency' , ( ) => {
94
+ it ( 'should throw a nice error' , async ( ) => {
95
95
jest . resetModules ( ) ;
96
96
jest . doMock ( 'graphql-ws' , ( ) => {
97
97
// eslint-disable-next-line no-throw-literal
98
98
throw { code : 'MODULE_NOT_FOUND' } ;
99
99
} ) ;
100
100
101
- expect ( ( ) => createWebsocketsFetcherFromUrl ( 'wss://example.com' ) ) . toThrow (
101
+ await expect (
102
+ createWebsocketsFetcherFromUrl ( 'wss://example.com' ) ,
103
+ ) . rejects . toThrow (
102
104
/ Y o u n e e d t o i n s t a l l t h e ' g r a p h q l - w s ' p a c k a g e t o u s e w e b s o c k e t s w h e n p a s s i n g a ' s u b s c r i p t i o n U r l ' / ,
103
105
) ;
104
106
} ) ;
0 commit comments