Skip to content

Tasks

Mock of Obsidian’s Tasks: collects promises in memory and awaits them all at once.

Import:

import { Tasks } from 'obsidian-test-mocks/obsidian';

Signature:

export class Tasks

Constructor

new Tasks()

Creates an empty task collection.

Methods

MethodReturnsDescription
add(callback)voidStarts a task by calling the callback immediately and collecting the promise it returns.
addPromise(promise)voidCollects an already-started promise.
asOriginalType__()TasksOriginalMock-only: views this mock as Obsidian's Tasks type.
constructor__()voidMock-only construction hook, called at the end of the constructor; a no-op meant for vi.spyOn(Tasks.prototype, 'constructor__').
isEmpty()booleanChecks whether no promise has been collected.
promise()Promise<unknown>Waits for every collected promise.
static create__()TasksMock-only factory: creates an empty task collection, spyable via vi.spyOn(Tasks, 'create__').
static fromOriginalType__(value)TasksMock-only: views a value typed as Obsidian's Tasks as this mock.