I can't claim credit for this, but incase you've stumbled upon this question and are looking for the answer here it is.
Declare io as a global in the bootstrap:
// test/boostrap.test.js
var client = require('../assets/js/dependencies/sails.io.js');
global.io = new client(require('socket.io-client'));
io.sails.url = 'http://localhost:1337/';
Then call them use them like so.
//test/callbacks.test.js
describe('socket request', function () {
it ('passport-local authentication should succeed if email and password valid', function (done) {
io.socket.post('/auth/local', { identifier: 'existing.user@email.com', password: 'admin1234' }, function (data, jwres) {
assert.equal(jwres.statusCode, 200);
done();
});
});
manpreet
Best Answer
2 years ago
I'm using sails.js v0.11.0 and I am just getting into unit testing. I can test normal controllers through http requests, but I have no idea where to start to test the same calls over a socket requests. If you have a good resource or a sample test using sockets that would be fantastic.