Skip to main content

@rbxts/expect > Proxy

Proxy type

A wrapper around a value T that provides meta context on index access.

Signature:

type Proxy<T> = T & ProxyInstance<T>;

References: ProxyInstance

Remarks

Proxies attach a listener to the __index metatable, which allows us to log the path of values accessed.

This allows expect() to populate the path automatically for you when checks fail.

You can create a proxy inline with createProxy(), or use withProxy() to have one automatically created and provided for you; whichever style you prefer.

Note that proxies are ONLY intended to be used on the left side of checks (ie; the actual value). Using a proxy on the right side (ie; the expected value) is undefined behavior, and depending on the method may result in a warning to your console.

Example

withProxy(person, (proxy) => {
expect(proxy.parent.cars).to.be.empty();
});

Error message:

Expected parent.cars to be empty, but it had 2 elements.