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()); }