Code Monkey home page Code Monkey logo

Comments (4)

infacq avatar infacq commented on July 28, 2024

unfortunately you have to define on your own if you run it on node environment

from asteroid.

Falieson avatar Falieson commented on July 28, 2024

Can someone provide more information about this? I made a stack overflow question about the same issue: https://stackoverflow.com/questions/45684811/jest-referenceerror-is-not-defined

  ● Test suite failed to run

    ReferenceError: WebSocket is not defined

      at Asteroid.init (node_modules/asteroid/lib/base-mixins/ddp.js:46:67)
      at node_modules/asteroid/lib/asteroid.js:72:33
      at Array.forEach (native)
      at new Asteroid (node_modules/asteroid/lib/asteroid.js:70:16)
      at Object.<anonymous> (src/config/asteroid.ts:6:16)
      at Object.<anonymous> (src/routes/Login.tsx:14:18)
      at Object.<anonymous> (src/routes/App.tsx:19:15)
      at Object.<anonymous> (src/routes/App.test.tsx:5:13)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

Test Suites: 1 failed, 1 total

I get this same error when I run jest test:

it('renders without crashing', () => {
  const div = document.createElement('div');
  ReactDOM.render(<App />, div);
});

Someone suggested this, but didn't work for me

const WebSocket = require('ws')
global.WebSocket= WebSocket

it('renders without crashing', () => {

  const div = document.createElement('div');
  ReactDOM.render(<App />, div);
});

from asteroid.

holmrenser avatar holmrenser commented on July 28, 2024

As far as the undefined websocket issue goes: you should define your own websocket in the class constructor like this:

const asteroid = require('asteroid');
const WebSocket = require('ws');

const Connection = asteroid.createClass()

const portal = new Connection({
    endpoint: 'ws://localhost:3000/websocket',
    SocketConstructor: WebSocket // <-------------- HERE
})

I have also commented this on the stack overflow issue: https://stackoverflow.com/a/45697156/6573438

from asteroid.

Falieson avatar Falieson commented on July 28, 2024

@holmrenser what fixed it for me was actually installing your PR: #122

The changes to SocketConstructor weren't necessary for me.

 ReferenceError: WebSocket is not defined

      at Asteroid.init (node_modules/asteroid/lib/base-mixins/ddp.js:46:67)

which is caused by (I think) trying to access the global.WebSocket which Jest doesn't have

Your PR declares it, removing the need to search for it in the global

PS
@holmrenser would you like to update your answer on SO and I'll approve it?

from asteroid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.