Comments (11)
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.
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.
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.
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.
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.
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.
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.
Looking good. I'm exited for the sailssocket take on $resource.
from angularsails.
This was exactly what I hoping for. Awesome job! Can't wait!
from angularsails.
It is now possible to use testing stuff with Karma ?
Thanks,
Gabriel
from angularsails.
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)
- No way to unsubscribe HOT 2
- Incompatibility with stable (0.10.5) version of sails? HOT 2
- what is the replacement for $sailsSocket.subscribe?
- Query params not functioning properly with sailsSocket request
- npm publish this please! HOT 2
- BLOCKER: TypeError: Cannot read property 'connected' of undefined
- _socketDefaults unused
- $sailsSocket .get is not a function HOT 1
- change in bower.json to report support for angular 1.4 HOT 3
- Missing a ) in dist/ngsails.io.js HOT 1
- "main": "index.js" in package.json does not exist HOT 2
- Publish 0.11.5 please! HOT 2
- $sailsSocket.get is not a function HOT 4
- Remove sails.io dependency
- $sailsSocket() error on get method HOT 1
- .put() shortcut is not defined HOT 1
- Adjusment for unsubscribing HOT 4
- Correct way injecting angularSails? HOT 1
- Support for Angular 2
- server error 500 req.isAuthenticated is not a function HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angularsails.