Skip to main content

@rbxts/expect > CustomMethodImpl

CustomMethodImpl type

The implementation of a expect() method.

Signature:

type CustomMethodImpl<T = unknown> = (source: Assertion<T>, actual: T, ...args: never[]) => ExpectMethodResult;

References: Assertion, ExpectMethodResult

Remarks

Takes in a source that maps to the Assertion that called this method (effectively the parent of the expect() call).

The actual value maps to the "actual" value that was provided when expect() was first called.

And ...args can be expanded to map however many arguments the method expects. Usually, this contains the "expected" value(s).

The method should return an ExpectMethodResult corresponding to if the check represented by the method was a pass or a fail.

Example

const baseMessage = new ExpectMessageBuilder(
`Expected ${place.name} to ${place.not} equal ${place.expected.value}`
)

const equal: CustomMethodImpl<defined> = (
_,
actual: defined,
expected: defined
) => {
const message = baseMessage.use().expectedValue(expected);

return actual === expected ? message.pass() : message.fail();
};