Skip to content

Commit 04652af

Browse files
committed
tests: fix tests
1 parent eb4d28f commit 04652af

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/Renderer/TaskLineRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Moment } from 'moment';
2-
import { App, Component, MarkdownRenderer } from 'obsidian';
2+
import { type App, Component, MarkdownRenderer } from 'obsidian';
33
import { GlobalFilter } from '../Config/GlobalFilter';
44
import { TASK_FORMATS, getSettings } from '../Config/Settings';
55
import type { QueryLayoutOptions } from '../Layout/QueryLayoutOptions';

tests/Renderer/QueryResultsRenderer.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import moment from 'moment';
55
import type { Task } from 'Task/Task';
6+
import type { App } from 'obsidian';
67
import { GlobalFilter } from '../../src/Config/GlobalFilter';
78
import { State } from '../../src/Obsidian/Cache';
89
import { QueryResultsRenderer } from '../../src/Renderer/QueryResultsRenderer';
@@ -32,13 +33,21 @@ afterEach(() => {
3233
resetSettings();
3334
});
3435

36+
/**
37+
* Since we don't use the app object's method or properties directly,
38+
* and just treat it as an "opaque object" for markdown rendering, there is
39+
* not a lot to mock in particular.
40+
*/
41+
const mockApp = {} as unknown as App;
42+
3543
function makeQueryResultsRenderer(source: string, tasksFile: TasksFile) {
3644
return new QueryResultsRenderer(
3745
'block-language-tasks',
3846
source,
3947
tasksFile,
4048
() => Promise.resolve(),
4149
null,
50+
mockApp,
4251
mockHTMLRenderer,
4352
);
4453
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
export const mockHTMLRenderer = async (text: string, element: HTMLSpanElement, _path: string) => {
1+
import type { App } from 'obsidian';
2+
3+
export const mockHTMLRenderer = async (_obsidianApp: App, text: string, element: HTMLSpanElement, _path: string) => {
24
// Contrary to the default mockTextRenderer(),
35
// instead of the rendered HTMLSpanElement.innerText,
46
// we need the plain HTML here like in TaskLineRenderer.renderComponentText(),
57
// to ensure that description and tags are retained.
68
element.innerHTML = text;
79
};
810

9-
export const mockTextRenderer = async (text: string, element: HTMLSpanElement, _path: string) => {
11+
export const mockTextRenderer = async (_obsidianApp: App, text: string, element: HTMLSpanElement, _path: string) => {
1012
element.innerText = text;
1113
};

tests/Renderer/TaskLineRenderer.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import moment from 'moment';
55

6+
import type { App } from 'obsidian';
67
import { DebugSettings } from '../../src/Config/DebugSettings';
78
import { GlobalFilter } from '../../src/Config/GlobalFilter';
89
import { resetSettings, updateSettings } from '../../src/Config/Settings';
@@ -22,6 +23,13 @@ import { mockHTMLRenderer, mockTextRenderer } from './RenderingTestHelpers';
2223
jest.mock('obsidian');
2324
window.moment = moment;
2425

26+
/**
27+
* Since we don't use the app object's method or properties directly,
28+
* and just treat it as an "opaque object" for markdown rendering, there is
29+
* not a lot to mock in particular.
30+
*/
31+
const mockApp = {} as unknown as App;
32+
2533
/**
2634
* Renders a task for test purposes and returns the rendered ListItem.
2735
*
@@ -41,6 +49,7 @@ async function renderListItem(
4149
) {
4250
const taskLineRenderer = new TaskLineRenderer({
4351
textRenderer: testRenderer ?? mockTextRenderer,
52+
obsidianApp: mockApp,
4453
obsidianComponent: null,
4554
parentUlElement: document.createElement('div'),
4655
taskLayoutOptions: taskLayoutOptions ?? new TaskLayoutOptions(),
@@ -84,6 +93,7 @@ describe('task line rendering - HTML', () => {
8493
const ulElement = document.createElement('ul');
8594
const taskLineRenderer = new TaskLineRenderer({
8695
textRenderer: mockTextRenderer,
96+
obsidianApp: mockApp,
8797
obsidianComponent: null,
8898
parentUlElement: ulElement,
8999
taskLayoutOptions: new TaskLayoutOptions(),

0 commit comments

Comments
 (0)