温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/test/default/MockPropertyContext
点击访问原文链接

class MockPropertyContext | Node.js node:test module | Bun

class MockPropertyContext | Node.js node:test module | BunBuildDocsReferenceGuidesBlogDiscord/node:test/default/MockPropertyContextMaccessCountPaccessesCoconstructorMmockImplementationMmockImplementationOnceMresetAccessesMrestore

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:test/default/MockPropertyContextMaccessCountPaccessesCoconstructorMmockImplementationMmockImplementationOnceMresetAccessesMrestore

class

test.default.MockPropertyContextclass MockPropertyContextPropertyType = any>
readonly accesses: { stack: Error; type: 'get' | 'set'; value: PropertyType }[]

A 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:

accessCount(): number;

This 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).

mockImplementation(value: PropertyType): void;

This function is used to change the value returned by the mocked property getter.

@param value

The new value to be set as the mocked property value.

{ const obj = { foo: 1 }; const prop = t.mock.property(obj, 'foo', 5); assert.strictEqual(obj.foo, 5); prop.mock.mockImplementationOnce(25); assert.strictEqual(obj.foo, 25); assert.strictEqual(obj.foo, 5); }); ```" data-algolia-static="false" data-algolia-merged="false" data-type="Method">mockImplementationOnce(value: PropertyType,onAccess?: number): void;

This 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 };

const prop = t.mock.property(obj, 'foo', 5);

assert.strictEqual(obj.foo, 5);
prop.mock.mockImplementationOnce(25);
assert.strictEqual(obj.foo, 25);
assert.strictEqual(obj.foo, 5);
});
@param value

The value to be used as the mock's implementation for the invocation number specified by onAccess.

@param 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.

resetAccesses(): void;

Resets the access history of the mocked property.

restore(): void;

Resets the implementation of the mock property to its original behavior. The mock can still be used after calling this function.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

class MockPropertyContext | Node.js node:test module | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    class MockPropertyContext | Node.js node:test module | Bun - 提供全网公开链接智能索引服务,快速访问目标内容,支持分类筛选和智能导航