Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

HttpBackendMock expectation fails for Uint8Array response #11200

Open
@gefilte

Description

@gefilte

This was broken starting in 1.2.27. The offending commit was 1426b02

-    if (data && !angular.isString(data)) return angular.equals(data, angular.fromJson(d));
+    if (data && !angular.isString(data)) {
+      return angular.equals(angular.fromJson(angular.toJson(data)), angular.fromJson(d));
+    }

My tests and my service use the same function to convert a payload into a U8IntArray:

function strToBinaryArray(str) {
  // This is the evil incantation to convert our string into a binary data array suitable for XHR.send()
  return new Uint8Array(
    Array.prototype.map.call(str, function byteValue(x) {
      return x.charCodeAt(0) & 0xff;
    }));
}

Now when I run my expectation with the expected payload washed through this function, I get this:

ERROR [karma]: Error: Expected POST adb-manager/adbs with different data
EXPECTED:     {"0":13,"1":10,"2":45, <CUT FOR BREVITY>,"length":434,"byteOffset":0,"buffer":{"byteLength":434},"byteLength":434}
GOT:      [object Uint8Array]
at http://localhost:9018/base/vendor/angular-mocks/angular-mocks.js?eb7eef4597d027fb2bbdc81cfbea2a5906c2e0e7:1150

If I revert the change from 1426b02 my spec passes.

This seems like a bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions