Skip to content

Commit eff2033

Browse files
committed
Add tests
1 parent 8b6c3d3 commit eff2033

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [3.0.0](https://github.com/react-native-community/fetch/compare/v2.0.0...v3.0.0) (2021-08-02)
6+
7+
8+
### ⚠ BREAKING CHANGES
9+
10+
* Response returns the instance rather than a promise in all cases
11+
12+
### Bug Fixes
13+
14+
* response correctly returns instance instead of promise ([8b6c3d3](https://github.com/react-native-community/fetch/commit/8b6c3d3ee97ba142c2bd1d341e2c072bac6262f8))
15+
516
## [2.0.0](https://github.com/react-native-community/fetch/compare/v1.0.2...v2.0.0) (2021-06-28)
617

718
### [1.0.2](https://github.com/react-native-community/fetch/compare/v1.0.1...v1.0.2) (2021-01-31)

package-lock.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-fetch-api",
33
"description": "A fetch API polyfill for React Native with text streaming support.",
4-
"version": "2.0.0",
4+
"version": "3.0.0",
55
"main": "fetch.js",
66
"author": {
77
"name": "André Costa Lima",

test/index.js

+40-11
Original file line numberDiff line numberDiff line change
@@ -1864,14 +1864,27 @@ test("fetch method", (t) => {
18641864
reactNative: { textStreaming: true },
18651865
});
18661866
const clone = res.clone();
1867-
const stream = await clone.body;
1868-
const text = new TextDecoder().decode(await drainStream(stream));
1867+
1868+
const resStream = await res.body;
1869+
const cloneStream = await clone.body;
1870+
const resText = new TextDecoder().decode(
1871+
await drainStream(resStream)
1872+
);
1873+
const cloneText = new TextDecoder().decode(
1874+
await drainStream(cloneStream)
1875+
);
18691876

18701877
t.ok(
1871-
stream instanceof ReadableStream,
1878+
resStream instanceof ReadableStream,
18721879
"Response implements streaming body"
18731880
);
1874-
t.eq(text, "Hello world!");
1881+
t.eq(resText, "Hello world!");
1882+
1883+
t.ok(
1884+
cloneStream instanceof ReadableStream,
1885+
"Response implements streaming body"
1886+
);
1887+
t.eq(cloneText, "Hello world!");
18751888
});
18761889

18771890
t.test("cloning blob response", async (t) => {
@@ -1882,8 +1895,11 @@ test("fetch method", (t) => {
18821895
},
18831896
});
18841897
const clone = res.clone();
1885-
const json = await clone.json();
1886-
t.eq(json.headers.accept, "application/json");
1898+
const resJson = res.json();
1899+
const cloneJson = await clone.json();
1900+
1901+
t.eq(resJson.headers.accept, "application/json");
1902+
t.eq(cloneJson.headers.accept, "application/json");
18871903
});
18881904

18891905
t.test("cloning array buffer response", async (t) => {
@@ -1894,15 +1910,28 @@ test("fetch method", (t) => {
18941910
},
18951911
});
18961912
const clone = res.clone();
1897-
const buf = await clone.arrayBuffer();
1913+
const resBuf = await res.arrayBuffer();
1914+
const cloneBuf = await clone.arrayBuffer();
18981915

1899-
t.ok(buf instanceof ArrayBuffer, "buf is an ArrayBuffer instance");
1900-
t.eq(buf.byteLength, 256, "buf.byteLength is correct");
1916+
t.ok(
1917+
resBuf instanceof ArrayBuffer,
1918+
"buf is an ArrayBuffer instance"
1919+
);
1920+
t.eq(resBuf.byteLength, 256, "buf.byteLength is correct");
1921+
1922+
t.ok(
1923+
cloneBuf instanceof ArrayBuffer,
1924+
"buf is an ArrayBuffer instance"
1925+
);
1926+
t.eq(cloneBuf.byteLength, 256, "buf.byteLength is correct");
19011927

19021928
const expected = Array.from({ length: 256 }, (_, i) => i);
1903-
const actual = Array.from(new Uint8Array(buf));
19041929

1905-
t.eq(actual, expected);
1930+
const resActual = Array.from(new Uint8Array(resBuf));
1931+
const cloneActual = Array.from(new Uint8Array(cloneBuf));
1932+
1933+
t.eq(resActual, expected);
1934+
t.eq(cloneActual, expected);
19061935
});
19071936
});
19081937
});

0 commit comments

Comments
 (0)