UNPKG

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