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

Commit 7692533

Browse files
authored
Improve fetch mock setup (#9511)
- Move from language to mock setup file - Add mock rule for stub image requests
1 parent 0f1738b commit 7692533

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

test/setup/setupLanguage.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ import * as languageHandler from "../../src/languageHandler";
2020
import en from "../../src/i18n/strings/en_EN.json";
2121
import de from "../../src/i18n/strings/de_DE.json";
2222

23-
fetchMock.config.overwriteRoutes = false;
24-
fetchMock.catch("");
25-
window.fetch = fetchMock.sandbox();
26-
2723
const lv = {
2824
"Save": "Saglabāt",
2925
"Uploading %(filename)s and %(count)s others|one": "Качване на %(filename)s и %(count)s друг",

test/setup/setupManualMocks.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
import fetchMock from "fetch-mock-jest";
1718
import { TextDecoder, TextEncoder } from "util";
1819

1920
// jest 27 removes setImmediate from jsdom
@@ -54,3 +55,9 @@ global.TextDecoder = TextDecoder;
5455

5556
// prevent errors whenever a component tries to manually scroll.
5657
window.HTMLElement.prototype.scrollIntoView = jest.fn();
58+
59+
// set up fetch API mock
60+
fetchMock.config.overwriteRoutes = false;
61+
fetchMock.catch("");
62+
fetchMock.get("/image-file-stub", "image file stub");
63+
window.fetch = fetchMock.sandbox();

0 commit comments

Comments
 (0)