项目原始demo,不改动
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

42 lines
1.0 KiB

  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. }