blob.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. var assert = require('assert');
  3. var hash = require('../index');
  4. if (typeof Blob !== 'undefined') {
  5. describe('hash()ing Blob objects', function() {
  6. var blob;
  7. before('create blob', function() {
  8. try {
  9. blob = new Blob(['ABC']);
  10. } catch(e) {
  11. // https://github.com/ariya/phantomjs/issues/11013
  12. if (!e.message.match(/'\[object BlobConstructor\]' is not a constructor/)) {
  13. throw e;
  14. }
  15. var builder = new WebKitBlobBuilder();
  16. builder.append('ABC');
  17. blob = builder.getBlob();
  18. }
  19. });
  20. it('should throw when trying to hash a blob', function() {
  21. assert.throws(function() {
  22. hash(blob);
  23. }, /not supported/);
  24. assert.throws(function() {
  25. hash({abcdef: blob});
  26. }, /not supported/);
  27. });
  28. it('should not throw when trying to hash a blob with ignoreUnknown', function() {
  29. var opt = {ignoreUnknown: true};
  30. assert.ok(validSha1.test(hash(blob, opt)), 'ignore Blob');
  31. assert.ok(validSha1.test(hash({abcdef: blob}, opt)), 'ignore Blob');
  32. });
  33. });
  34. }