Run eslint on test/

This commit is contained in:
0x1eef 2023-09-29 15:25:24 -03:00
parent e498c5b6e2
commit 7f15dceef7
4 changed files with 22 additions and 22 deletions

View file

@ -1,13 +1,13 @@
import React from "react"; import React from "react";
import '@testing-library/jest-dom' import '@testing-library/jest-dom';
import { render, screen, act, waitFor } from "@testing-library/react"; import { render, screen, act } from "@testing-library/react";
import { App } from "~/components/App"; import { App } from "~/components/App";
import { getMessage } from "./mocks/chrome.i18n"; import { getMessage } from "./mocks/chrome.i18n";
import { success, error, loading } from "./mocks/fetch"; import { success, error, loading } from "./mocks/fetch";
describe("App.tsx", () => { describe("App.tsx", () => {
beforeEach(() => { beforeEach(() => {
const chrome: any = {i18n: {getMessage}}; const chrome: any = { i18n: { getMessage } };
global.chrome = chrome; global.chrome = chrome;
}); });
@ -16,18 +16,18 @@ describe("App.tsx", () => {
}); });
describe("when the request is loading", () => { describe("when the request is loading", () => {
beforeEach(() => { global.fetch = loading }); beforeEach(() => { global.fetch = loading; });
afterEach(() => { global.fetch = undefined }); afterEach(() => { global.fetch = undefined; });
test("loading text is rendered", () => { test("loading text is rendered", () => {
render(<App/>); render(<App/>);
expect(screen.getByText("Loading...")).toBeInTheDocument(); expect(screen.getByText("Loading...")).toBeInTheDocument();
}) });
}); });
describe("when the request is a success", () => { describe("when the request is a success", () => {
beforeEach(() => { global.fetch = success }); beforeEach(() => { global.fetch = success; });
afterEach(() => { global.fetch = undefined }); afterEach(() => { global.fetch = undefined; });
test("response is rendered", async () => { test("response is rendered", async () => {
await act(() => render(<App/>)); await act(() => render(<App/>));
@ -36,8 +36,8 @@ describe("App.tsx", () => {
}); });
describe("when the request throws an error", () => { describe("when the request throws an error", () => {
beforeEach(() => { global.fetch = error }); beforeEach(() => { global.fetch = error; });
afterEach(() => { global.fetch = undefined }); afterEach(() => { global.fetch = undefined; });
test("error is rendered", async () => { test("error is rendered", async () => {
await act(() => render(<App/>)); await act(() => render(<App/>));

View file

@ -1,5 +1,5 @@
import React from "react"; import React from "react";
import '@testing-library/jest-dom' import '@testing-library/jest-dom';
import { render, screen } from "@testing-library/react"; import { render, screen } from "@testing-library/react";
import { ErrorRenderer } from "~/components/ErrorRenderer"; import { ErrorRenderer } from "~/components/ErrorRenderer";
import { getMessage } from "./mocks/chrome.i18n"; import { getMessage } from "./mocks/chrome.i18n";
@ -8,7 +8,7 @@ describe("ErrorRenderer.tsx", () => {
const error = new Error("This is an example error message"); const error = new Error("This is an example error message");
beforeEach(() => { beforeEach(() => {
const chrome: any = {i18n: {getMessage}}; const chrome: any = { i18n: { getMessage } };
global.chrome = chrome; global.chrome = chrome;
render(<ErrorRenderer error={error}/>); render(<ErrorRenderer error={error}/>);
}); });

View file

@ -1,12 +1,12 @@
import React from "react"; import React from "react";
import '@testing-library/jest-dom' import '@testing-library/jest-dom';
import { render, screen } from "@testing-library/react"; import { render, screen } from "@testing-library/react";
import { ResponseRenderer } from "~/components/ResponseRenderer"; import { ResponseRenderer } from "~/components/ResponseRenderer";
import { getMessage } from "./mocks/chrome.i18n"; import { getMessage } from "./mocks/chrome.i18n";
describe("ResponseRenderer.tsx", () => { describe("ResponseRenderer.tsx", () => {
beforeEach(() => { beforeEach(() => {
const chrome: any = {i18n: {getMessage}}; const chrome: any = { i18n: { getMessage } };
global.chrome = chrome; global.chrome = chrome;
}); });
@ -23,7 +23,7 @@ describe("ResponseRenderer.tsx", () => {
}; };
describe("when isTorExitNode is false", () => { describe("when isTorExitNode is false", () => {
const response = {...defaultResponse}; const response = { ...defaultResponse };
beforeEach(() => { beforeEach(() => {
render(<ResponseRenderer response={response}/>); render(<ResponseRenderer response={response}/>);
@ -56,7 +56,7 @@ describe("ResponseRenderer.tsx", () => {
}); });
describe("when isTorExitNode is true", () => { describe("when isTorExitNode is true", () => {
const response = {...defaultResponse, isTorExitNode: true}; const response = { ...defaultResponse, isTorExitNode: true };
beforeEach(() => { beforeEach(() => {
render(<ResponseRenderer response={response}/>); render(<ResponseRenderer response={response}/>);
@ -65,6 +65,6 @@ describe("ResponseRenderer.tsx", () => {
test("isTorExitNode is rendered as Yes", () => { test("isTorExitNode is rendered as Yes", () => {
expect(screen.getByText("Tor exit node")).toBeInTheDocument(); expect(screen.getByText("Tor exit node")).toBeInTheDocument();
expect(screen.getByText("Yes")).toBeInTheDocument(); expect(screen.getByText("Yes")).toBeInTheDocument();
}) });
}); });
}); });

View file

@ -1,4 +1,4 @@
import {TServerResponse} from "~/lib/response"; import { TServerResponse } from "~/lib/response";
export function success(_path: RequestInfo | URL, _options?: RequestInit) { export function success(_path: RequestInfo | URL, _options?: RequestInit) {
const json = () => ( const json = () => (
@ -11,18 +11,18 @@ export function success(_path: RequestInfo | URL, _options?: RequestInit) {
YourFuckingTorExit: false YourFuckingTorExit: false
}) })
) )
)) ));
return new Promise<any>((resolve) => { return new Promise<any>((resolve) => {
resolve({status: 200, json}); resolve({ status: 200, json });
}); });
} }
export function error(_path: RequestInfo | URL, _options?: RequestInit) { export function error(_path: RequestInfo | URL, _options?: RequestInit) {
return new Promise<any>(() => { return new Promise<any>(() => {
throw new Error("Request error"); throw new Error("Request error");
}) });
}; }
export function loading(_path: RequestInfo | URL, _options?: RequestInit) { export function loading(_path: RequestInfo | URL, _options?: RequestInit) {
return new Promise<any>(() => null); return new Promise<any>(() => null);