diff --git a/lib/index.js b/lib/index.js index 9df7ae59db..b54bbb5b14 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,6 +3,7 @@ */ var utf8 = require('./utf8'); +var hasBinary = require('has-binary'); var after = require('after'); var keys = require('./keys'); @@ -217,7 +218,7 @@ exports.encodePayload = function (packets, supportsBinary, callback) { supportsBinary = null; } - if (supportsBinary) { + if (supportsBinary && hasBinary(packets)) { return exports.encodePayloadAsBinary(packets, callback); } diff --git a/test/browser/index.js b/test/browser/index.js index 7a60125aeb..07a75f47d8 100644 --- a/test/browser/index.js +++ b/test/browser/index.js @@ -9,21 +9,3 @@ if (Blob) { } require('./base64_object.js'); - -// General browser only tests -var parser = require('../../'); -var encode = parser.encodePacket; -var decode = parser.decodePacket; -var encPayload = parser.encodePayload; -var decPayload = parser.decodePayload; - -describe('basic functionality', function () { - it('should encode string payloads as strings even if binary supported', function (done) { - encPayload([{ type: 'ping' }, { type: 'post' }], true, function(data) { - expect(data).to.be.a('string'); - done(); - }); - }); -}); - - diff --git a/test/parser.js b/test/parser.js index bdd525f830..553803af7f 100644 --- a/test/parser.js +++ b/test/parser.js @@ -165,6 +165,15 @@ module.exports = function(parser) { }); }); + describe('basic functionality', function () { + it('should encode string payloads as strings even if binary supported', function (done) { + encPayload([{ type: 'ping' }, { type: 'post' }], true, function(data) { + expect(data).to.be.a('string'); + done(); + }); + }); + }); + describe('encoding and decoding', function () { var seen = 0; it('should encode/decode packets', function (done) {