TypeScript fixes

This commit is contained in:
0x1eef 2024-08-03 05:01:20 -03:00
parent c2e5925ced
commit ffa1eeb734
4 changed files with 12 additions and 9 deletions

View file

@ -6,18 +6,21 @@ import { getMessage } from "./mocks/chrome.i18n";
import { success, error, loading } from "./mocks/fetch";
describe("App.tsx", () => {
const globalChrome = global.chrome;
const globalFetch = global.fetch;
beforeEach(() => {
const chrome: any = { i18n: { getMessage } };
global.chrome = chrome;
});
afterEach(() => {
global.chrome = undefined;
global.chrome = globalChrome;
});
describe("when the request is loading", () => {
beforeEach(() => { global.fetch = loading; });
afterEach(() => { global.fetch = undefined; });
afterEach(() => { global.fetch = globalFetch; });
test("loading text is rendered", () => {
render(<App/>);
@ -27,7 +30,7 @@ describe("App.tsx", () => {
describe("when the request is a success", () => {
beforeEach(() => { global.fetch = success; });
afterEach(() => { global.fetch = undefined; });
afterEach(() => { global.fetch = globalFetch; });
test("response is rendered", async () => {
await act(() => render(<App/>));
@ -37,7 +40,7 @@ describe("App.tsx", () => {
describe("when the request throws an error", () => {
beforeEach(() => { global.fetch = error; });
afterEach(() => { global.fetch = undefined; });
afterEach(() => { global.fetch = globalFetch; });
test("error is rendered", async () => {
await act(() => render(<App/>));

View file

@ -5,6 +5,7 @@ import { ErrorRenderer } from "~/components/ErrorRenderer";
import { getMessage } from "./mocks/chrome.i18n";
describe("ErrorRenderer.tsx", () => {
const globalChrome = global.chrome;
const error = new Error("This is an example error message");
beforeEach(() => {
@ -14,7 +15,7 @@ describe("ErrorRenderer.tsx", () => {
});
afterEach(() => {
global.chrome = undefined;
global.chrome = globalChrome;
});
test("an error is rendered", () => {

View file

@ -5,13 +5,15 @@ import { ResponseRenderer } from "~/components/ResponseRenderer";
import { getMessage } from "./mocks/chrome.i18n";
describe("ResponseRenderer.tsx", () => {
const globalChrome = global.chrome;
beforeEach(() => {
const chrome: any = { i18n: { getMessage } };
global.chrome = chrome;
});
afterEach(() => {
global.chrome = undefined;
global.chrome = globalChrome;
});
const defaultResponse = {

View file

@ -1,14 +1,11 @@
{
"compilerOptions": {
"strict": true,
"strictNullChecks": false,
"module": "commonjs",
"target": "ES2020",
"noImplicitAny": true,
"moduleResolution": "node",
"esModuleInterop": true,
"jsx": "react",
"allowJs": true,
"lib": [ "ES2020", "DOM" ],
"baseUrl": "src/",
"paths": { "~/*": ["js/*"] },