arnaucube
arnaucube/socketioMEANseedPublic Self-hosted repository
socketioMEANseed/server/node_modules/has-binary/test.js
server/node_modules/has-binary/test.jsRaw
 1
 2var hasBinary = require('./');
 3var assert = require('better-assert');
 4var fs = require('fs');
 5
 6describe('has-binarydata', function(){
 7
 8  it('should work with buffer', function(){
 9    assert(hasBinary(fs.readFileSync('./test.js')));
10  });
11
12  it('should work with an array that does not contain binary', function() {
13    var arr = [1, 'cool', 2];
14    assert(!hasBinary(arr));
15  });
16
17  it('should work with an array that contains a buffer', function() {
18    var arr = [1, new Buffer('asdfasdf', 'utf8'), 2];
19    assert(hasBinary(arr));
20  });
21
22  it('should work with an object that does not contain binary', function() {
23    var ob = {a: 'a', b: [], c: 1234, toJSON: '{\"a\": \"a\"}'};
24    assert(!hasBinary(ob));
25  });
26
27  it('should work with an object that contains a buffer', function() {
28    var ob = {a: 'a', b: new Buffer('abc'), c: 1234, toJSON: '{\"a\": \"a\"}'};
29    assert(hasBinary(ob));
30  });
31
32  it('should work with null', function() {
33    assert(!hasBinary(null));
34  });
35
36  it('should work with undefined', function() {
37    assert(!hasBinary(undefined));
38  });
39
40  it('should work with a complex object that contains undefined and no binary', function() {
41    var ob = {
42      x: ['a', 'b', 123],
43      y: undefined,
44      z: {a: 'x', b: 'y', c: 3, d: null},
45      w: []
46    };
47    assert(!hasBinary(ob));
48  });
49
50  it('should work with a complex object that contains undefined and binary', function() {
51    var ob = {
52      x: ['a', 'b', 123],
53      y: undefined,
54      z: {a: 'x', b: 'y', c: 3, d: null},
55      w: [],
56      bin: new Buffer('xxx')
57    };
58    assert(hasBinary(ob));
59  });
60
61  if (global.ArrayBuffer) {
62      it('should work with an ArrayBuffer', function() {
63        assert(hasBinary(new ArrayBuffer()));
64      });
65  }
66
67  if (global.Blob) {
68     it('should work with a Blob', function() {
69        assert(hasBinary(new Blob()));
70     });
71  }
72
73});