twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

index.js (3391B)


      1 var Blob = require('../');
      2 var expect = require('expect.js');
      3 
      4 describe('blob', function() {
      5   if (!Blob) {
      6     it('should not have a blob or a blob builder in the global namespace, or blob should not be a constructor function if the module exports false', function() {
      7       try {
      8         var ab = (new Uint8Array(5)).buffer;
      9         global.Blob([ab]);
     10         expect().fail('Blob shouldn\'t be constructable');
     11       } catch (e) {}
     12 
     13       var BlobBuilder = global.BlobBuilder
     14         || global.WebKitBlobBuilder
     15         || global.MSBlobBuilder
     16         || global.MozBlobBuilder;
     17       expect(BlobBuilder).to.be(undefined);
     18     });
     19   } else {
     20     it('should encode a proper sized blob when given a string argument', function() {
     21       var b = new Blob(['hi']);
     22       expect(b.size).to.be(2);
     23     });
     24 
     25     it('should encode a blob with proper size when given two strings as arguments', function() {
     26       var b = new Blob(['hi', 'hello']);
     27       expect(b.size).to.be(7);
     28     });
     29 
     30     it('should encode arraybuffers with right content', function(done) {
     31       var ary = new Uint8Array(5);
     32       for (var i = 0; i < 5; i++) ary[i] = i;
     33       var b = new Blob([ary.buffer]);
     34       var fr = new FileReader();
     35       fr.onload = function() {
     36         var newAry = new Uint8Array(this.result);
     37         for (var i = 0; i < 5; i++) expect(newAry[i]).to.be(i);
     38         done();
     39       };
     40       fr.readAsArrayBuffer(b);
     41     });
     42 
     43     it('should encode typed arrays with right content', function(done) {
     44       var ary = new Uint8Array(5);
     45       for (var i = 0; i < 5; i++) ary[i] = i;
     46       var b = new Blob([ary]);
     47       var fr = new FileReader();
     48       fr.onload = function() {
     49         var newAry = new Uint8Array(this.result);
     50         for (var i = 0; i < 5; i++) expect(newAry[i]).to.be(i);
     51         done();
     52       };
     53       fr.readAsArrayBuffer(b);
     54     });
     55 
     56     it('should encode sliced typed arrays with right content', function(done) {
     57       var ary = new Uint8Array(5);
     58       for (var i = 0; i < 5; i++) ary[i] = i;
     59       var b = new Blob([ary.subarray(2)]);
     60       var fr = new FileReader();
     61       fr.onload = function() {
     62         var newAry = new Uint8Array(this.result);
     63         for (var i = 0; i < 3; i++) expect(newAry[i]).to.be(i + 2);
     64         done();
     65       };
     66       fr.readAsArrayBuffer(b);
     67     });
     68 
     69     it('should encode with blobs', function(done) {
     70       var ary = new Uint8Array(5);
     71       for (var i = 0; i < 5; i++) ary[i] = i;
     72       var b = new Blob([new Blob([ary.buffer])]);
     73       var fr = new FileReader();
     74       fr.onload = function() {
     75         var newAry = new Uint8Array(this.result);
     76         for (var i = 0; i < 5; i++) expect(newAry[i]).to.be(i);
     77         done();
     78       };
     79       fr.readAsArrayBuffer(b);
     80     });
     81 
     82     it('should enode mixed contents to right size', function() {
     83       var ary = new Uint8Array(5);
     84       for (var i = 0; i < 5; i++) ary[i] = i;
     85       var b = new Blob([ary.buffer, 'hello']);
     86       expect(b.size).to.be(10);
     87     });
     88 
     89     it('should accept mime type', function() {
     90       var b = new Blob(['hi', 'hello'], { type: 'text/html' });
     91       expect(b.type).to.be('text/html');
     92     });
     93 
     94     it('should be an instance of constructor', function() {
     95       var b = new Blob(['hi']);
     96       expect(b).to.be.a(Blob);
     97       expect(b).to.be.a(global.Blob);
     98     });
     99   }
    100 });