toHaveProperty

Bun

Symbol

Matchers.toHaveProperty

toHaveProperty(keyPath: string | number | string | number[], value?: unknown): void

Asserts that a value has a property with the expected name, and value if provided.

@param keyPath

the expected property name or path, or an index

@param value

the expected property value, if provided

expect(new Set()).toHaveProperty("size");
expect(new Uint8Array()).toHaveProperty("byteLength", 0);
expect({ kitchen: { area: 20 }}).toHaveProperty("kitchen.area", 20);
expect({ kitchen: { area: 20 }}).toHaveProperty(["kitchen", "area"], 20);