obsidian-test-mocks
v8.1.0
Published
Comprehensive test mocks for the Obsidian API.
Maintainers
Readme
obsidian-test-mocks
Comprehensive test mocks for the Obsidian plugin API. Provides in-memory implementations of every class and function in obsidian.d.ts, plus prototype extensions Obsidian adds to DOM/JS builtins. The package is tested with 100% code coverage (lines, branches, functions, and statements) enforced on every build.
Installation
npm install --save-dev obsidian-test-mocksPeer dependencies: obsidian, plus @codemirror/state, @codemirror/view and moment, which obsidian already brings into the tree. They are peers so the mocks share your project's one CodeMirror copy rather than nesting a second one.
Entry Points
| Import path | Description |
| ---------------------------------------------------- | ------------------------------------------------------------------------- |
| obsidian-test-mocks/obsidian | Mocks for every class/function in obsidian.d.ts |
| obsidian-test-mocks/setup | Exports setup() / teardown() for prototype extensions and globals |
| obsidian-test-mocks/vitest-setup | One-stop Vitest setup file: calls setup() + mocks the obsidian module |
| obsidian-test-mocks/jest-setup | Jest setup file: calls setup() for prototype extensions and globals |
| obsidian-test-mocks/obsidian-typings/setup | Deprecated no-op. Bridging is no longer needed |
| obsidian-test-mocks/obsidian-typings/vitest-setup | Deprecated no-op. Bridging is no longer needed |
| obsidian-test-mocks/obsidian-typings/jest-setup | Deprecated no-op. Bridging is no longer needed |
Quick start
Add the Vitest setup files — they patch prototypes/globals and mock obsidian automatically:
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
setupFiles: ['obsidian-test-mocks/vitest-setup']
}
});Then build a vault in memory and exercise the code under test:
import { App } from 'obsidian-test-mocks/obsidian';
const app = App.createConfigured__({
files: {
'notes/daily/2024-01-01.md': '# New Year'
}
});Documentation
The full documentation — guides plus the complete, searchable API reference generated from the library's TSDoc — is published at mnaoumov.dev/obsidian-test-mocks.
- API reference
- Getting Started
- Test Runner Setup
- Importing the Mocks
- Creating Mock Instances
- Strict Mocks
- Type Bridging
- Using with
obsidian-typings - Design Principles
See also
| Library | Features | How obsidian-test-mocks differs |
| --- | --- | --- |
| jest-environment-obsidian | Jest environment and preset; shims the obsidian module; reimplements Obsidian's prototype extensions; warnings for unsupported usage | Same goal as jest-environment-obsidian, which is archived at Obsidian 1.1.16: mocks the whole current obsidian.d.ts with in-memory behavior; supports Vitest as well as Jest; omits its warnings |
| obsidian-mock | Mock classes for Obsidian's API, imported from obsidian-mock in place of obsidian; TypeScript types; test utilities | Same goal as obsidian-mock, which is not published on npm: published on npm; mocks the obsidian module itself through a setup file; adds Obsidian's prototype extensions to DOM and JS builtins |
| obsidian-test-kit | Vitest stub aliased as obsidian; jsdom polyfills for DOM helpers, moment, globals and animations; @testing-library/jest-dom matchers; stub loads in a node environment | Same goal as obsidian-test-kit: mocks every obsidian.d.ts member, with an in-memory vault, metadata cache and workspace; supports Jest as well as Vitest; omits its matchers and its DOM-free node stub |
Last searched for similar libraries on 2026-11-04.
Changelog
All notable changes to this project will be documented in the CHANGELOG.
Support
Filing an issue (for AI agents and humans)
Open issues through the issue forms, not as blank issues.
Filing from the CLI or the API (gh issue create --body, or an AI agent filing for you) skips the form, and gh issue create --template cannot load an issue form. In that case, open the matching form in .github/ISSUE_TEMPLATE/, copy every field as a ### <label> heading in the form's order, and fill in each one. Always state the version you used and your operating system.
