Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 8e66ac4

Browse files
committed
first steps to mock
1 parent 1df5b70 commit 8e66ac4

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

jest.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module.exports = {
22
preset: "ts-jest",
33
testEnvironment: "jsdom",
4-
roots: ["src"],
5-
modulePaths: ["src"],
6-
moduleDirectories: ["node_modules"],
4+
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
5+
moduleDirectories: ["node_modules", "src"],
76
};

src/DatabaseView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class DatabaseView extends TextFileView implements HoverParent {
124124
stateManager: this.plugin.getStateManager(this.file)
125125
}
126126

127-
let table = createDatabase(tableProps);
127+
const table = createDatabase(tableProps);
128128
this.tableContainer = this.contentEl.createDiv(StyleClasses.TABLE_CONTAINER);
129129
ReactDOM.render(table, this.tableContainer);
130130
LOGGER.info(`<=initDatabase ${this.file.path}`);

src/__tests__/reactTable.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { render, screen } from "@testing-library/react";
2+
import { Vault } from 'obsidian';
3+
import { Database } from 'components/index/Database';
4+
import {TableDataType} from 'cdm/FolderModel';
5+
import { makeData } from "mock/mockUtils";
6+
import React from "react";
7+
8+
jest.mock("obsidian");
9+
const VaultMock = Vault as jest.MockedClass<typeof Vault>;
10+
test("Render without crashing", () => {
11+
const mockedTableData:TableDataType = makeData(10);
12+
render(<Database {...mockedTableData} />);
13+
const titleLabel = screen.getByText(" title");
14+
expect(titleLabel).toBeInTheDocument();
15+
});

src/components/index/Database.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function createDatabase(tableProps:TableDataType): JSX.Element {
1515
);
1616
}
1717

18-
function Database(tableProps:TableDataType){
18+
export function Database(tableProps:TableDataType){
1919
const [state, dataDispatch] = useReducer(databaseReducer, tableProps);
2020

2121
useEffect(() => {

src/parsers/embedYamlHandlers/FolderHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AbstractYamlHandler } from 'parsers/embedYamlHandlers/AbstractYamlPropertyHandler';
2-
import { App, normalizePath } from "obsidian";
2+
import { normalizePath } from "obsidian";
33
export class FolderHandler extends AbstractYamlHandler {
44
handlerName: string = 'folder';
55
public handle(yaml: any): [string, string][] {

0 commit comments

Comments
 (0)