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:
Nick K
2021-04-20 16:07:38 +02:00
committed by GitHub
parent 3b12a39ea2
commit eed6a1dddd
3 changed files with 21 additions and 2 deletions
+4 -2
View File
@@ -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({
+1
View File
@@ -160,6 +160,7 @@ class Blob {
static [Symbol.hasInstance](object) {
return (
object &&
typeof object === 'object' &&
typeof object.stream === 'function' &&
object.stream.length === 0 &&
+16
View File
@@ -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);
});