Giter Site home page Giter Site logo

Comments (5)

austinknight avatar austinknight commented on May 22, 2024 1

Yes, the second example is what I am talking about. Adding a triggerError method on the server mock would be awesome!

from mock-socket.

thoov avatar thoov commented on May 22, 2024 1

@TimMurnaghan Thanks for reminding me. Just published 7.1.0 where you can call server.simulate('error');. Here is the PR: #184

from mock-socket.

thoov avatar thoov commented on May 22, 2024

Right now the only way to trigger the onerror is by trying to connect to an invalid or closed connection. Something like this:

it('.onerror will be fired', (done) => {
  // uncomment the following line and onerror will not be triggered
  //const server = new Server('ws://localhost:8080');
  const socket = new WebSocket('ws://localhost:8080');

  socket.onerror = function error() {
    assert.ok(true, 'websocket does not have a server to connect to');
    done();
  };
});

If you are looking for something on the server to manually trigger an error like so:

it('errors can be sent from the server', (done) => {
  const server = new Server('ws://localhost:8080');
  const socket = new WebSocket('ws://localhost:8080');

  server.on('connection',  () => {
    server.triggerError() // this does not exist right now
  })

  socket.onerror = function error() {
    assert.ok(true, 'the server has sent an error');
    done();
  };
});

I can add the functionality. Just let me know.

from mock-socket.

stevenxxiu avatar stevenxxiu commented on May 22, 2024

@thoov I don't think the first is triggered even when using websockets instead of socket io. A way to do this would be great!

from mock-socket.

TimMurnaghan avatar TimMurnaghan commented on May 22, 2024

@thoov I guess that triggerError never happened?
Sorry to add a "me too", but this is an important function of a mock library. I want to exercise the error handling of my client code (which, given the way developers think, is often broken). And it's definitely your second case. I don't want an invalid endpoint - it should be valid - but causing errors in some cases.

Should I do it and make a pull request? Or is it big enough that it will cause conflicts with your refactor?

from mock-socket.

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.