Add nullish values checking in Symbol.hasInstance (#82)
* Add nullish values checking in Symbol.hasInstance * Fix for a test description * Add an extension. * Disable unicorn/import-index rule. * Fix a typo
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
const {statSync, createReadStream} = require('fs');
|
||||
const Blob = require('./index.js');
|
||||
const DOMException = require('domexception');
|
||||
|
||||
// eslint-disable-next-line unicorn/import-index
|
||||
const Blob = require('./index.js');
|
||||
|
||||
/**
|
||||
* @param {string} path filepath on the disk
|
||||
* @returns {Blob}
|
||||
@@ -27,7 +29,7 @@ class BlobDataItem {
|
||||
this.mtime = options.mtime;
|
||||
}
|
||||
|
||||
// Slicing arguments is first validated and formated
|
||||
// Slicing arguments is first validated and formated
|
||||
// to not be out of range by Blob.prototype.slice
|
||||
slice(start, end) {
|
||||
return new BlobDataItem({
|
||||
|
||||
@@ -160,6 +160,7 @@ class Blob {
|
||||
|
||||
static [Symbol.hasInstance](object) {
|
||||
return (
|
||||
object &&
|
||||
typeof object === 'object' &&
|
||||
typeof object.stream === 'function' &&
|
||||
object.stream.length === 0 &&
|
||||
|
||||
@@ -160,3 +160,19 @@ test('Reading after modified should fail', async t => {
|
||||
const error = await blob.text().catch(error => error);
|
||||
t.is(error.name, 'NotReadableError');
|
||||
});
|
||||
|
||||
test('Blob-ish class is an instance of Blob', t => {
|
||||
class File {
|
||||
stream() { }
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
return 'File';
|
||||
}
|
||||
}
|
||||
|
||||
t.true(new File() instanceof Blob);
|
||||
});
|
||||
|
||||
test('Instanceof check returns false for nullish values', t => {
|
||||
t.false(null instanceof Blob);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user