Add tests
This commit is contained in:
parent
aa61b2fb76
commit
0612312e13
21 changed files with 642 additions and 113 deletions
46
src/test/lib/fetcher.spec.tsx
Normal file
46
src/test/lib/fetcher.spec.tsx
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { ok } from "assert";
|
||||
import useFetcher, {
|
||||
defaults,
|
||||
handleResponse,
|
||||
handleError,
|
||||
fetchProduction,
|
||||
fetchDevelopment,
|
||||
} from "../../lib/fetcher";
|
||||
|
||||
describe("fetcher.tsx", () => {
|
||||
it("Tests handleResponse", () => {});
|
||||
|
||||
it("Tests handleError", () => {
|
||||
expect(handleError("apps", Error("Test!"))).toEqual({
|
||||
...defaults.app,
|
||||
error: "Test!",
|
||||
});
|
||||
|
||||
expect(handleError("bookmark", Error("Test!"))).toEqual({
|
||||
...defaults.bookmark,
|
||||
error: "Test!",
|
||||
});
|
||||
|
||||
expect(handleError("searchProvider", Error("Test!"))).toEqual({
|
||||
...defaults.search,
|
||||
error: "Test!",
|
||||
});
|
||||
|
||||
expect(handleError("theme", Error("Test!"))).toEqual({
|
||||
...defaults.theme,
|
||||
error: "Test!",
|
||||
});
|
||||
|
||||
expect(handleError("imprint", Error("Test!"))).toEqual({
|
||||
...defaults.imprint,
|
||||
error: "Test!",
|
||||
});
|
||||
|
||||
expect(handleError("greeter", Error("Test!"))).toEqual({
|
||||
...defaults.greeter,
|
||||
error: "Test!",
|
||||
});
|
||||
|
||||
expect(handleError("", Error("Test!"))).toEqual(undefined);
|
||||
});
|
||||
});
|
|
@ -1,8 +1,4 @@
|
|||
import selectedTheme, {
|
||||
getTheme,
|
||||
IThemeProps,
|
||||
setTheme,
|
||||
} from "../../lib/theme";
|
||||
import { getTheme, IThemeProps, setTheme } from "../../lib/theme";
|
||||
|
||||
const props: IThemeProps = {
|
||||
label: "Classic",
|
||||
|
@ -12,33 +8,47 @@ const props: IThemeProps = {
|
|||
backgroundColor: "#ffffff",
|
||||
};
|
||||
|
||||
const theme = JSON.stringify(props);
|
||||
const location: Location = window.location;
|
||||
const setup = () => {
|
||||
Object.defineProperty(window, "localStorage", {
|
||||
value: {
|
||||
getItem: jest.fn(() => JSON.stringify(props)),
|
||||
setItem: jest.fn(() => null),
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
delete window.location;
|
||||
|
||||
window.location = {
|
||||
...location,
|
||||
reload: jest.fn(),
|
||||
};
|
||||
};
|
||||
|
||||
describe("theme.tsx", () => {
|
||||
beforeEach(() => {
|
||||
Object.defineProperty(window, "localStorage", {
|
||||
value: {
|
||||
getItem: jest.fn(() => null),
|
||||
setItem: jest.fn(() => null),
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("setTheme test", () => {
|
||||
setTheme(theme);
|
||||
setup();
|
||||
|
||||
setTheme(props);
|
||||
expect(window.localStorage.setItem).toHaveBeenCalledTimes(1);
|
||||
expect(window.localStorage.setItem).toHaveBeenCalledWith("theme", theme);
|
||||
expect(window.localStorage.setItem).toHaveBeenCalledWith(
|
||||
"theme",
|
||||
JSON.stringify(props),
|
||||
);
|
||||
expect(window.location.reload).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("getTheme test", () => {
|
||||
const themeTest = getTheme();
|
||||
it("Tests getTheme", () => {
|
||||
setup();
|
||||
|
||||
let themeTest = getTheme();
|
||||
expect(themeTest).toEqual(props);
|
||||
});
|
||||
|
||||
it("selectedTheme test", () => {
|
||||
const themeTest = selectedTheme;
|
||||
expect(themeTest).toEqual(props);
|
||||
it("Tests getTheme with empty parameters", () => {
|
||||
localStorage.setItem("theme", "");
|
||||
expect(getTheme()).toEqual({});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue