Skip to content

Commit a6fa544

Browse files
Fix internal assertion encountered when testing with jsdom. (#8142)
Fix internal assertion due to Buffer value not evaluating to instanceof Uint8Array, encountered when testing with jsdom.
1 parent 9297ef3 commit a6fa544

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

.changeset/hot-turkeys-promise.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/firestore": patch
3+
---
4+
5+
Fix internal assertion due to Buffer value not evaluating to instanceof Uint8Array, encountered when testing with jsdom.

packages/firestore/src/remote/serializer.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,14 @@ export function fromBytes(
262262
return ByteString.fromBase64String(value ? value : '');
263263
} else {
264264
hardAssert(
265-
value === undefined || value instanceof Uint8Array,
266-
'value must be undefined or Uint8Array'
265+
value === undefined ||
266+
// Check if the value is an instance of both Buffer and Uint8Array,
267+
// despite the fact that Buffer extends Uint8Array. In some
268+
// environments, such as jsdom, the prototype chain of Buffer
269+
// does not indicate that it extends Uint8Array.
270+
value instanceof Buffer ||
271+
value instanceof Uint8Array,
272+
'value must be undefined, Buffer, or Uint8Array'
267273
);
268274
return ByteString.fromUint8Array(value ? value : new Uint8Array());
269275
}

0 commit comments

Comments
 (0)