From a6fa544173aeeee9d4f35e1ebd36fe2c2f461d19 Mon Sep 17 00:00:00 2001 From: Mark Duckworth <1124037+MarkDuckworth@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:52:22 -0600 Subject: [PATCH] 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. --- .changeset/hot-turkeys-promise.md | 5 +++++ packages/firestore/src/remote/serializer.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/hot-turkeys-promise.md diff --git a/.changeset/hot-turkeys-promise.md b/.changeset/hot-turkeys-promise.md new file mode 100644 index 00000000000..3c05a8b0ba4 --- /dev/null +++ b/.changeset/hot-turkeys-promise.md @@ -0,0 +1,5 @@ +--- +"@firebase/firestore": patch +--- + +Fix internal assertion due to Buffer value not evaluating to instanceof Uint8Array, encountered when testing with jsdom. diff --git a/packages/firestore/src/remote/serializer.ts b/packages/firestore/src/remote/serializer.ts index 175c3110f60..63860a88972 100644 --- a/packages/firestore/src/remote/serializer.ts +++ b/packages/firestore/src/remote/serializer.ts @@ -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()); }