Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Go to Latest
class TestDoubleBuilder
import { TestDoubleBuilder } from "https://deno.land/x/rhum@v2.1.0-rc.1/src/test_double_builder.ts";

This class contains the methods to help build most of what a test double needs.

Constructors

new
TestDoubleBuilder(constructorFn: Constructor<OriginalClass>)

Construct an object of this class.

Type Parameters

OriginalClass

Properties

protected
constructor_args: unknown[]

A list of args the class constructor takes. This is used to instantiate the original with args (if needed).

protected
constructor_fn: Constructor<OriginalClass>

The constructor function of the objet to create a test double out of.

protected
native_methods: string[]

A list of native methods on an original object that should not be modified. When adding an original's methods to a test double, the copying process uses this array to skip adding these native methods with tracking. There is no reason to track these methods.

Methods

protected
addOriginalMethodWithoutTracking<TestDoubleInterface>(
original: OriginalClass,
testDouble: TestDoubleInterface,
method: string,
): void

Add an original object's method to a a test double without doing anything else.

protected
addOriginalProperties<TestDoubleInterface>(original: OriginalClass, testDouble: TestDoubleInterface): void

Add an original object's properties to the test double.

protected
addOriginalProperty<TestDoubleInterface>(
original: OriginalClass,
testDouble: TestDoubleInterface,
property: string,
): void

Add an original object's property to the test double.

protected
getAllFunctionNames(obj: OriginalClass): string[]

Get all functions from the original so they can be added to the test double.

protected
getAllPropertyNames(obj: OriginalClass): string[]

Get all properties from the original so they can be added to the test double.

withConstructorArgs(...args: unknown[]): this

Before constructing the fake object, track any constructor function args that need to be passed in when constructing the fake object.