Closed jtenner closed 5 years ago
This is fixed on the master branch already
Is this actually fixed? If I give fetchMock
const body = "someData"
fetchMock.mockResponseOnce(body);
const blob = new Blob([body], {type: 'text/plain;charset=utf-8'});
// do fetch and compare Blobs
I get:
expect(received).toEqual(expected)
Expected value to equal:
{"payload": {Symbol(impl): {"_buffer": {"data": [115, 111, 109, 101, 68, 97, 116, 97], "type": "Buffer"}, "type": "text/plain;charset=utf-8", Symbol(wrapper): [Circular]}}
Received:
{"payload": {Symbol(type): "text/plain;charset=utf-8", Symbol(buffer): {"data": [115, 111, 109, 101, 68, 97, 116, 97], "type": "Buffer"}}
Difference:
- Expected
+ Received
@@ -1,9 +1,9 @@
Object {
"payload": Blob {
- Symbol(impl): BlobImpl {
- "_buffer": Object {
+ Symbol(type): "text/plain;charset=utf-8",
+ Symbol(buffer): Object {
"data": Array [
115,
111,
109,
101,
@@ -12,14 +12,11 @@
116,
97,
],
"type": "Buffer",
},
- "type": "text/plain;charset=utf-8",
- Symbol(wrapper): [Circular],
},
- },
I probably need to read up on Blobs to understand this difference here. Do you know how I could make assertions of the Blob type that jest-fetch-mock returns from response.blob()
?
I realize this problem is because of the way the
Response
is mocked insidenode-fetch
, it creates an instance of a customBlob
class, and thus TypeErrors like this occur:The following expectation outright fails.
Is there any way to expose the internal
Blob
class and override the globalBlob
so thatinstanceof
checks will work?