Skip to content

Commit d8a640c

Browse files
committed
test: adjust testing
1 parent 57975dd commit d8a640c

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
| Statements | Branches | Functions | Lines |
1212
| --------------------------------------------------------------------- | ------------------------------------------------------------------- | -------------------------------------------------------------------- | ---------------------------------------------------------------- |
13-
| ![Statements](https://img.shields.io/badge/statements-88.12%25-yellow.svg) | ![Branches](https://img.shields.io/badge/branches-71.88%25-red.svg) | ![Functions](https://img.shields.io/badge/functions-81.25%25-yellow.svg) | ![Lines](https://img.shields.io/badge/lines-87.91%25-yellow.svg) |
13+
| ![Statements](https://img.shields.io/badge/statements-88.35%25-yellow.svg) | ![Branches](https://img.shields.io/badge/branches-73.53%25-red.svg) | ![Functions](https://img.shields.io/badge/functions-81.25%25-yellow.svg) | ![Lines](https://img.shields.io/badge/lines-88.17%25-yellow.svg) |
1414

1515
## Table of Contents
1616

src/__tests__/index.spec.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// @ts-nocheck
21
/* eslint-disable no-plusplus */
3-
/* eslint-disable jest/no-focused-tests */
42
/* eslint-disable no-prototype-builtins */
53
import fetch from 'node-fetch';
64
import { ReadableStream } from 'web-streams-polyfill/ponyfill';
@@ -17,8 +15,6 @@ const expectedKeys = [
1715
'isInProgress',
1816
];
1917

20-
const scheme = global.Response;
21-
2218
beforeAll(() => {
2319
global.window.fetch = fetch as Extract<WindowOrWorkerGlobalScope, 'fetch'>;
2420
global.Response = Response;
@@ -28,9 +24,9 @@ beforeAll(() => {
2824
describe('useDownloader successes', () => {
2925
beforeAll(() => {
3026
process.env.REACT_APP_DEBUG_MODE = 'true';
31-
window.URL.createObjectURL = () => 'true';
32-
window.URL.revokeObjectURL = () => 'true';
33-
window.webkitURL.createObjectURL = () => 'true';
27+
window.URL.createObjectURL = () => 'true';
28+
window.URL.revokeObjectURL = () => 'true';
29+
window.webkitURL.createObjectURL = () => 'true';
3430

3531
const pieces = [
3632
new Uint8Array([65, 98, 99, 32, 208]), // "Abc " and first byte of "й"
@@ -43,7 +39,7 @@ describe('useDownloader successes', () => {
4339
'content-length': '456',
4440
});
4541

46-
global.window.fetch = jest.fn(() =>
42+
global.window.fetch = () =>
4743
Promise.resolve({
4844
ok: true,
4945
headers: {
@@ -56,7 +52,9 @@ describe('useDownloader successes', () => {
5652

5753
return {
5854
read() {
59-
return Promise.resolve<ReadableStreamDefaultReadResult<Uint8Array>>(
55+
return Promise.resolve<
56+
ReadableStreamDefaultReadResult<Uint8Array>
57+
>(
6058
i < pieces.length
6159
? { value: pieces[i++], done: false }
6260
: { value: undefined, done: true }
@@ -65,9 +63,8 @@ describe('useDownloader successes', () => {
6563
};
6664
},
6765
},
68-
blob: () => Promise.resolve(new Blob),
69-
})
70-
);
66+
blob: () => Promise.resolve(new Blob()),
67+
}) as Extract<WindowOrWorkerGlobalScope, 'fetch'>;
7168
});
7269

7370
it('should run through', async () => {
@@ -104,7 +101,11 @@ describe('useDownloader failures', () => {
104101
it('should start download with no OK', async () => {
105102
const { result, waitForNextUpdate } = renderHook(() => useDownloader());
106103

107-
global.window.fetch = jest.fn(() => Promise.resolve({ ok: false })) as Extract<WindowOrWorkerGlobalScope, 'fetch'>;
104+
global.window.fetch = () =>
105+
Promise.resolve({ ok: false }) as Extract<
106+
WindowOrWorkerGlobalScope,
107+
'fetch'
108+
>;
108109

109110
const downloadSpy = jest.spyOn(result.current, 'download');
110111

@@ -127,7 +128,9 @@ describe('useDownloader failures', () => {
127128
process.env.REACT_APP_DEBUG_MODE = 'true';
128129
const { result, waitForNextUpdate } = renderHook(() => useDownloader());
129130

130-
global.window.fetch = jest.fn(() => Promise.resolve({ ok: false })) as Extract<WindowOrWorkerGlobalScope, 'fetch'>;
131+
global.window.fetch = jest.fn(() =>
132+
Promise.resolve({ ok: false })
133+
) as Extract<WindowOrWorkerGlobalScope, 'fetch'>;
131134

132135
const downloadSpy = jest.spyOn(result.current, 'download');
133136

@@ -219,6 +222,7 @@ describe('useDownloader failures', () => {
219222
});
220223

221224
it('should test with msSaveBlob', () => {
225+
console.error = jest.fn();
222226
const msSaveBlobSpy = jest.spyOn(window.navigator, 'msSaveBlob');
223227

224228
jsDownload(new Blob(['abcde']), 'test');

0 commit comments

Comments
 (0)