1
+ import { vi } from 'vitest' ;
1
2
import { parse } from 'graphql' ;
2
3
import {
3
4
isSubscriptionWithName ,
7
8
8
9
import 'isomorphic-fetch' ;
9
10
10
- jest . mock ( 'graphql-ws' ) ;
11
+ vi . mock ( 'graphql-ws' ) ;
11
12
12
- jest . mock ( 'subscriptions-transport-ws' ) ;
13
+ vi . mock ( 'subscriptions-transport-ws' ) ;
13
14
14
15
import { createClient } from 'graphql-ws' ;
15
16
@@ -44,7 +45,7 @@ describe('isSubscriptionWithName', () => {
44
45
45
46
describe ( 'createWebsocketsFetcherFromUrl' , ( ) => {
46
47
afterEach ( ( ) => {
47
- jest . resetAllMocks ( ) ;
48
+ vi . resetAllMocks ( ) ;
48
49
} ) ;
49
50
50
51
it ( 'creates a websockets client using provided url' , async ( ) => {
@@ -64,7 +65,7 @@ describe('createWebsocketsFetcherFromUrl', () => {
64
65
65
66
describe ( 'getWsFetcher' , ( ) => {
66
67
afterEach ( ( ) => {
67
- jest . resetAllMocks ( ) ;
68
+ vi . resetAllMocks ( ) ;
68
69
} ) ;
69
70
it ( 'provides an observable wsClient when custom wsClient option is provided' , async ( ) => {
70
71
createClient . mockReturnValue ( true ) ;
@@ -92,10 +93,17 @@ describe('getWsFetcher', () => {
92
93
93
94
describe ( 'missing `graphql-ws` dependency' , ( ) => {
94
95
it ( 'should throw a nice error' , async ( ) => {
95
- jest . resetModules ( ) ;
96
- jest . doMock ( 'graphql-ws' , ( ) => {
97
- // eslint-disable-next-line no-throw-literal
98
- throw { code : 'MODULE_NOT_FOUND' } ;
96
+ vi . resetModules ( ) ;
97
+ vi . doMock ( 'graphql-ws' , ( ) => {
98
+ // While throwing an error directly inside this callback `code` is attached in `cause`
99
+ // property e.g. `Error.cause.code`, so I throw an error on calling `createClient` instead
100
+
101
+ return {
102
+ createClient : vi . fn ( ) . mockImplementation ( ( ) => {
103
+ // eslint-disable-next-line no-throw-literal
104
+ throw { code : 'MODULE_NOT_FOUND' } ;
105
+ } ) ,
106
+ } ;
99
107
} ) ;
100
108
101
109
await expect (
0 commit comments