You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

  1. var Blob = require('../');
  2. var expect = require('expect.js');
  3. if (!Blob) {
  4. return;
  5. }
  6. describe('blob', function() {
  7. it('should encode a proper sized blob when given a string argument', function() {
  8. var b = new Blob(['hi']);
  9. expect(b.size).to.be(2);
  10. });
  11. it('should encode a blob with proper size when given two strings as arguments', function() {
  12. var b = new Blob(['hi', 'hello']);
  13. expect(b.size).to.be(7);
  14. });
  15. it('should encode arraybuffers with right content', function() {
  16. var ary = new Uint8Array(5);
  17. for (var i = 0; i < 5; i++) ary[i] = i;
  18. var b = new Blob([ary.buffer]);
  19. var fr = new FileReader();
  20. fr.onload = function() {
  21. var newAry = new Uint8Array(this.result);
  22. for (var i = 0; i < 5; i++) expect(newAry[i]).to.be(i);
  23. };
  24. });
  25. it('should encode with blobs', function() {
  26. var ary = new Uint8Array(5);
  27. for (var i = 0; i < 5; i++) ary[i] = i;
  28. var b = new Blob([new Blob([ary.buffer])]);
  29. var fr = new FileReader();
  30. fr.onload = function() {
  31. var newAry = new Uint8Array(this.result);
  32. for (var i = 0; i < 5; i++) expect(newAry[i]).to.be(i);
  33. };
  34. });
  35. it('should enode mixed contents to right size', function() {
  36. var ary = new Uint8Array(5);
  37. for (var i = 0; i < 5; i++) ary[i] = i;
  38. var b = new Blob([ary.buffer, 'hello']);
  39. expect(b.size).to.be(10);
  40. });
  41. it('should accept mime type', function() {
  42. var b = new Blob(['hi', 'hello'], { type: 'text/html' });
  43. expect(b.type).to.be('text/html');
  44. });
  45. });