/** * Tests for loadPdfJs stub function. * * loadPdfJs is a stub that: * 1. Returns a resolved Promise (resolving to undefined) * 2. Emits a one-shot console.warn on first call per page-load * * The function exists for Obsidian API compatibility. Plugins that call * loadPdfJs() to initialize PDF.js rendering will not crash, but * actual PDF rendering is not supported (PDF.js is not bundled). */ import { describe, it, expect, vi, beforeEach } from 'vitest' import { loadPdfJs, _resetWarnedStubs } from '../obsidian-stubs' beforeEach(() => { _resetWarnedStubs() vi.restoreAllMocks() }) describe('loadPdfJs', () => { it('returns a resolved Promise (undefined)', async () => { const result = await loadPdfJs() expect(result).toBeUndefined() }) it('emits a console.warn on first call', async () => { const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}) await loadPdfJs() expect(warnSpy).toHaveBeenCalledOnce() expect(warnSpy).toHaveBeenCalledWith( expect.stringContaining('[Reams] loadPdfJs') ) }) it('emits console.warn only once per page-load (warn-once)', async () => { const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}) await loadPdfJs() await loadPdfJs() await loadPdfJs() expect(warnSpy).toHaveBeenCalledOnce() }) it('can be called multiple times without error', async () => { // Suppress console.warn for cleaner test output vi.spyOn(console, 'warn').mockImplementation(() => {}) // Should not throw, all calls resolve to undefined expect(await loadPdfJs()).toBeUndefined() expect(await loadPdfJs()).toBeUndefined() expect(await loadPdfJs()).toBeUndefined() }) })