Skip to content

Commit

Permalink
Fix internal assertion encountered when testing with jsdom. (#8142)
Browse files Browse the repository at this point in the history
Fix internal assertion due to Buffer value not evaluating to instanceof Uint8Array, encountered when testing with jsdom.
  • Loading branch information
MarkDuckworth committed Apr 9, 2024
1 parent 9297ef3 commit a6fa544
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-turkeys-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/firestore": patch
---

Fix internal assertion due to Buffer value not evaluating to instanceof Uint8Array, encountered when testing with jsdom.
10 changes: 8 additions & 2 deletions packages/firestore/src/remote/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,14 @@ export function fromBytes(
return ByteString.fromBase64String(value ? value : '');
} else {
hardAssert(
value === undefined || value instanceof Uint8Array,
'value must be undefined or Uint8Array'
value === undefined ||
// Check if the value is an instance of both Buffer and Uint8Array,
// despite the fact that Buffer extends Uint8Array. In some
// environments, such as jsdom, the prototype chain of Buffer
// does not indicate that it extends Uint8Array.
value instanceof Buffer ||
value instanceof Uint8Array,
'value must be undefined, Buffer, or Uint8Array'
);
return ByteString.fromUint8Array(value ? value : new Uint8Array());
}
Expand Down

0 comments on commit a6fa544

Please sign in to comment.