Giter Site home page Giter Site logo

Comments (11)

 avatar commented on June 3, 2024

I'm in the same situation. For now I'm using spies, but that isn't a very long term solution.

mockSocket = $injector.get('$sailsSocket');
spyOn(mockSocket, 'get').and.returnValue(mockedStuff);

from angularsails.

robwormald avatar robwormald commented on June 3, 2024

Hey All -

I’m actually (this minute) working out the testing stuff with Karma - should work more or less like the $httpBackend Mocks available in angular-mocks.

Hopefully within the next couple of days.

Rob

On Aug 13, 2014, at 7:05 PM, Kyle McGuire [email protected] wrote:

I'm in the same situation. For now I'm using spies, but that isn't a very long term solution.

mockSocket = $injector.get('$sailsSocket');
spyOn(mockSocket, 'get').and.returnValue(mockedStuff);

Reply to this email directly or view it on GitHub.

from angularsails.

robwormald avatar robwormald commented on June 3, 2024

Actually, since there’s interest here:

I’m a little torn about the best way to go about this.

The $http service in the ng module injects the $httpBackend service - the non mock version is a simple wrapper that exposes a single interface.

The current $sailsSocket does a similar thing - it injects a $sailsSocketBackend that pipes the requests over socket.io, as opposed to XHR.

The simplest / most straightforward solution (which is basically what I’m doing) is injecting a similar mock $sailsSocketBackend, which is more or less a clone of the mock $httpBackend. This would enable you do to do:

sailsSocketMock.expectGET(“/foo/1").respond({“id” : 1});
This work for everybody?

On Aug 13, 2014, at 7:05 PM, Kyle McGuire [email protected] wrote:

I'm in the same situation. For now I'm using spies, but that isn't a very long term solution.

mockSocket = $injector.get('$sailsSocket');
spyOn(mockSocket, 'get').and.returnValue(mockedStuff);

Reply to this email directly or view it on GitHub.

from angularsails.

samlroberts avatar samlroberts commented on June 3, 2024

I think that's an ideal solution. Is that something you're adding now, or is that already available? Based on the documentation here that was my initial understanding of how it currently worked.

from angularsails.

 avatar commented on June 3, 2024

sailsSocketMock.expectGET(“/foo/1").respond({“id” : 1});

Is how I was hoping it would work. I think since the $sailsSocket interface so closely resembles that of $http it makes sense for it to present a similar testing interface.

Thanks Rob!

from angularsails.

robwormald avatar robwormald commented on June 3, 2024

Update for y’all :

Did a bunch of cleanup this week, just pushed a new branch (resource) to the repo. DON’T USE IT (yet) as some things are still in flux, but I thought you might like to see this. I basically duplicated the $httpBackend, and also copied over the $http test suite.

I’ve commented out a few tests I haven’t worked out yet, but as of now it’s passing near enough the whole $http suite.

Usage looks like this https://github.com/balderdashy/angularSails/blob/resource/test/unit/sailsSocketHttp.spec.js - so if that’s the kind of thing y’all wanted, you should be able to use it very soon.

Note that the $sailsSocket is very much a clone of $http, so what this specific suite is testing is that I get expected results at the $httpBackend level. The $httpBackend service is a light wrapper around XHR, so the $sailsBackend equivalent is a lightweight wrapper around socket.io (and in theory, could be used for any transport in the future (pure web sockets) and I’ve gotta write a new suite for that before this is ready to go.

Input welcome

R

On Aug 14, 2014, at 10:52 AM, Kyle McGuire [email protected] wrote:

sailsSocketMock.expectGET(“/foo/1").respond({“id” : 1});

Is how I was hoping it would work. I think since the $sailsSocket interface so closely resembles that of http it makes sense for it to present a similar testing interface.

Thanks Rob!


Reply to this email directly or view it on GitHub.

from angularsails.

mikermcneil avatar mikermcneil commented on June 3, 2024

I think this is precisely the right approach.

Mike's phone

On Aug 15, 2014, at 12:54, Rob Wormald [email protected] wrote:

Update for y’all :

Did a bunch of cleanup this week, just pushed a new branch (resource) to the repo. DON’T USE IT (yet) as some things are still in flux, but I thought you might like to see this. I basically duplicated the $httpBackend, and also copied over the $http test suite.

I’ve commented out a few tests I haven’t worked out yet, but as of now it’s passing near enough the whole $http suite.

Usage looks like this https://github.com/balderdashy/angularSails/blob/resource/test/unit/sailsSocketHttp.spec.js - so if that’s the kind of thing y’all wanted, you should be able to use it very soon.

Note that the $sailsSocket is very much a clone of $http, so what this specific suite is testing is that I get expected results at the $httpBackend level. The $httpBackend service is a light wrapper around XHR, so the $sailsBackend equivalent is a lightweight wrapper around socket.io (and in theory, could be used for any transport in the future (pure web sockets) and I’ve gotta write a new suite for that before this is ready to go.

Input welcome

R

On Aug 14, 2014, at 10:52 AM, Kyle McGuire [email protected] wrote:

sailsSocketMock.expectGET(“/foo/1").respond({“id” : 1});

Is how I was hoping it would work. I think since the $sailsSocket interface so closely resembles that of http it makes sense for it to present a similar testing interface.

Thanks Rob!


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub.

from angularsails.

 avatar commented on June 3, 2024

Looking good. I'm exited for the sailssocket take on $resource.

from angularsails.

samlroberts avatar samlroberts commented on June 3, 2024

This was exactly what I hoping for. Awesome job! Can't wait!

from angularsails.

Gab-Metzger avatar Gab-Metzger commented on June 3, 2024

It is now possible to use testing stuff with Karma ?

Thanks,
Gabriel

from angularsails.

ddelrio1986 avatar ddelrio1986 commented on June 3, 2024

Did this stuff ever make it into any releases? Did it ever make it into the master branch? If you can let me know where you left off I'd love to finish stuff for you. Please respond and let us know what's going on with this.

from angularsails.

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.