Skip to content

IconValue

Mock of Obsidian’s IconValue: a string value holding an icon id.

Import:

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

Signature:

export class IconValue extends StringValue

Extends: StringValue

Constructor

new IconValue(value?: string)

Creates an icon value.

Properties

PropertyTypeDescription
datastringThe wrapped primitive. Obsidian's own name for it, which is why this carries no __ suffix (L4).
(Inherited from StringValue)
iconstringThe lucide icon name standing for this value's type.
typestringThe value type's identifier, 'String' - Obsidian's own name for this class of value.
(Inherited from StringValue)

Methods

MethodReturnsDescription
asOriginalType__()ValueOriginalMock-only: views this mock as Obsidian's Value type.
(Inherited from StringValue)
asOriginalType2__()NotNullValueOriginalMock-only: views this mock as Obsidian's NotNullValue type.
(Inherited from StringValue)
asOriginalType3__()PrimitiveValueOriginal<string>Mock-only: views this mock as Obsidian's PrimitiveValue type.
(Inherited from StringValue)
asOriginalType4__()StringValueOriginalMock-only: views this mock as Obsidian's StringValue type.
(Inherited from StringValue)
asOriginalType5__()IconValueOriginalMock-only: views this mock as Obsidian's IconValue type.
constructor__()voidMock-only construction hook, called at the end of the constructor; a no-op meant for vi.spyOn(Value.prototype, 'constructor__').
(Inherited from StringValue)
constructor2__()voidMock-only construction hook, called at the end of the constructor; a no-op meant for vi.spyOn(NotNullValue.prototype, 'constructor2__').
(Inherited from StringValue)
constructor3__(_value)voidMock-only construction hook, called at the end of the constructor; a no-op meant for vi.spyOn(PrimitiveValue.prototype, 'constructor3__').
(Inherited from StringValue)
constructor4__(_value?)voidMock-only construction hook, called at the end of the constructor; a no-op meant for vi.spyOn(StringValue.prototype, 'constructor4__').
(Inherited from StringValue)
constructor5__(_value)voidMock-only construction hook, called at the end of the constructor; a no-op meant for vi.spyOn(IconValue.prototype, 'constructor5__').
equals(other)booleanCompares this value with another of the same type, as Obsidian does: by strict equality of the wrapped primitives.
(Inherited from StringValue)
equals(_other)booleanCompares this value with another of the same type.
(Inherited from StringValue)
isTruthy()booleanReports whether the value counts as true in a condition, by JavaScript truthiness of the wrapped primitive.
(Inherited from StringValue)
keys()string[]Lists the property keys StringValue.objectAccess answers for.
(Inherited from StringValue)
looseEquals(other)booleanLoosely compares this value with a value of any type, as Obsidian does: any other primitive value whose wrapped primitive is LOOSELY equal to this one. The == is Obsidian's own and is the whole point of the override - it is what makes BooleanValue(true) loosely equal NumberValue(1) and StringValue('1').
(Inherited from StringValue)
looseEquals(_other)booleanCompares this value with a value of any type.
(Inherited from StringValue)
objectAccess(key)null | ValueReads a named sub-property of this value.
(Inherited from StringValue)
objectAccess(_key)null | ValueReads a named sub-property of this value, as a Bases formula's . access does.
(Inherited from StringValue)
renderTo(el, _context)voidRenders the icon into an element, as Obsidian does: the SVG the icon id resolves to, falling back to question-mark-glyph when the id is unknown, and rendering NOTHING when even that does not resolve.

In practice the mock takes that last branch: src/internal/icon-registry.ts starts EMPTY on purpose - Obsidian's Lucide set and its own glyphs are deliberately not bundled - so both lookups answer null unless a test has registered the id with addIcon. That is a property of the registry rather than of this method: register question-mark-glyph and every unknown icon renders it, exactly as in the app.
toString()stringConverts the value to its display string.
(Inherited from StringValue)
static create__(value?)StringValueMock-only factory: creates a string value, spyable via vi.spyOn(StringValue, 'create__').
(Inherited from StringValue)
static create2__(value?)IconValueMock-only factory: creates an icon value, spyable via vi.spyOn(IconValue, 'create2__'). The subclass variant of StringValue.create__.
static equals(this, a, b)booleanCompares two possibly-null values, exactly as Obsidian's own static does: the same object is equal to itself, a missing value equals only another missing one, two values of DIFFERENT classes are never equal, and otherwise a.equals(b) decides. The missing test is Obsidian's own truthiness check rather than a null one, so an undefined the declared signature does not admit, but a JavaScript consumer can still pass, is answered rather than dereferenced.

The class test is what lets each subclass's equals assume the other side is its own shape: PrimitiveValue.equals reads other.data, DateValue.equals reads other.time, and neither has to guard, because a value of another class never reaches them through this static.
(Inherited from StringValue)
static fromOriginalType__(value)ValueMock-only: views a value typed as Obsidian's Value as this mock.
(Inherited from StringValue)
static fromOriginalType2__(value)NotNullValueMock-only: views a value typed as Obsidian's NotNullValue as this mock.
(Inherited from StringValue)
static fromOriginalType3__(value)PrimitiveValue<string>Mock-only: views a value typed as Obsidian's PrimitiveValue as this mock.
(Inherited from StringValue)
static fromOriginalType4__(value)StringValueMock-only: views a value typed as Obsidian's StringValue as this mock.
(Inherited from StringValue)
static fromOriginalType5__(value)IconValueMock-only: views a value typed as Obsidian's IconValue as this mock.
static looseEquals(this, a, b)booleanLoosely compares two possibly-null values, exactly as Obsidian's own static does: the same object is loosely equal to itself, a missing value only to another missing one - by the truthiness test the static equals above describes - and otherwise strict equality is tried first, then a.looseEquals(b), then b.looseEquals(a).

BOTH directions are tried, and that matters wherever the two sides' overrides disagree: it is what lets a one-element ListValue unwrap against a non-list whichever side it is passed on, and what lets a DateValue and a StringValue holding its text compare equal in either order.
(Inherited from StringValue)