MockPropertyContext
[<Interface>]
type MockPropertyContext<'PropertyType> =
abstract member accesses: Item<'PropertyType> array
static member Create (accesses: Item<'PropertyType> array, accessCount: unit -> float, mockImplementation: 'PropertyType -> unit, mockImplementationOnce: Action<'PropertyType,float option>, resetAccesses: unit -> unit, restore: unit -> unit) : MockPropertyContext<'PropertyType>
abstract member accessCount () : float
abstract member mockImplementation (value: 'PropertyType) : unit
abstract member mockImplementationOnce (value: 'PropertyType, ?onAccess: float) : unit
abstract member resetAccesses () : unit
abstract member restore () : unit| Assembly | Xantham.Fable.Node |
| Attributes | [<Interface>] |
Declared inside
Accesses |
Properties
abstract member accesses: Item<'PropertyType> array
abstract member accesses: Item<'PropertyType> arrayA getter that returns a copy of the internal array used to track accesses (get/set) to the mocked property. Each entry in the array is an object with the following properties:
Methods
static member Create (accesses: Item<'PropertyType> array, accessCount: unit -> float, mockImplementation: 'PropertyType -> unit, mockImplementationOnce: Action<'PropertyType,float option>, resetAccesses: unit -> unit, restore: unit -> unit) : MockPropertyContext<'PropertyType>abstract member accessCount () : float
abstract member accessCount () : floatThis function returns the number of times that the property was accessed. This function is more efficient than checking ctx.accesses.length because ctx.accesses is a getter that creates a copy of the internal access tracking array.
Returns. The number of times that the property was accessed (read or written).
abstract member mockImplementation (value: 'PropertyType) : unit
abstract member mockImplementation (value: 'PropertyType) : unitThis function is used to change the value returned by the mocked property getter.
| Parameter | |
|---|---|
value | The new value to be set as the mocked property value. |
abstract member mockImplementationOnce (value: 'PropertyType, ?onAccess: float) : unit
abstract member mockImplementationOnce (value: 'PropertyType, ?onAccess: float) : unitThis function is used to change the behavior of an existing mock for a single invocation. Once invocation onAccess has occurred, the mock will revert to whatever behavior it would have used had mockImplementationOnce() not been called.
The following example creates a mock function using t.mock.property(), calls the mock property, changes the mock implementation to a different value for the next invocation, and then resumes its previous behavior.
test('changes a mock behavior once', (t) => {
const obj = { foo: 1 };
assert.strictEqual(obj.foo, 5);
prop.mock.mockImplementationOnce(25);
assert.strictEqual(obj.foo, 25);
assert.strictEqual(obj.foo, 5);
});
| Parameter | |
|---|---|
value | The value to be used as the mock's implementation for the invocation number specified by onAccess. |
onAccess | The invocation number that will use value. If the specified invocation has already occurred then an exception is thrown. Default: The number of the next invocation. |