You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm trying to close the websocket transport after I've done with the socket in the jest unittests.
However, I run into this error.
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From src/tests.ts.
at node_modules/viem/utils/rpc/webSocket.ts:28:31
at getSocket (node_modules/viem/utils/rpc/webSocket.ts:28:25)
at setup (node_modules/viem/utils/rpc/socket.ts:160:24)
at Timeout._onTimeout (node_modules/viem/utils/rpc/socket.ts:147:13)
console.error
TypeError: WebSocket is not a constructor
Here's the minimal script to reproduce the issue
...
consturl= 'wss://....`
// create websocket rpc clientconstclient=createPublicClient({transport: webSocket(url),});
....
....// close the socket when no longer neededconstsocket=awaitclient.transport?.getSocket();if(socket){socket.close();}
I've also tried another way to close the socket with this
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm trying to close the websocket transport after I've done with the socket in the jest unittests.
However, I run into this error.
Here's the minimal script to reproduce the issue
I've also tried another way to close the socket with this
Still run into the same error.
May I know how can close the websocket transport after I've done with my test cases?
Node Version:
v22.11.0
Viem Version:
2.33.1
Thank you very much.
Beta Was this translation helpful? Give feedback.
All reactions