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

Expect.extend method | bun:test module | Bun

Expect.extend method | bun:test module | BunBuildDocsReferenceGuidesBlogDiscord/bun:test/Expect/extendMextend

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/bun:test/Expect/extendMextend

method

test.Expect.extendextendM>(matchers: ExpectExtendMatchersM>): void;

Register new custom matchers.

@param matchers

An object containing the matchers to register, where each key is the matcher name, and its value the implementation function. The function must satisfy: (actualValue, ...matcherInstantiationArguments) => { pass: true|false, message: () => string }

expect.extend({
toBeWithinRange(actual, min, max) {
if (typeof actual !== 'number' || typeof min !== 'number' || typeof max !== 'number')
throw new Error('Invalid usage');
const pass = actual >= min && actual max;
return {
pass: pass,
message: () => `expected ${this.utils.printReceived(actual)} ` +
(pass ? `not to be`: `to be`) + ` within range ${this.utils.printExpected(`${min} .. ${max}`)}`,
};
},
});

test('some test', () => {
expect(50).toBeWithinRange(0, 100); // will pass
expect(50).toBeWithinRange(100, 200); // will fail
expect(50).toBe(expect.toBeWithinRange(0, 100)); // will pass
expect(50).toBe(expect.not.toBeWithinRange(100, 200)); // will pass
});
Referenced typestype ExpectExtendMatchersM> = { [K in keyof M]: k extends keyof CustomMatchersDetected ? CustomMatcherunknown, ParametersCustomMatchersDetected[k]>> : CustomMatcherunknown, any[]> }

If the types has been defined through declaration merging, enforce it. Otherwise enforce the generic custom matcher signature.

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 →

Expect.extend method | bun:test module | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for method bun:test.Expect.extend | Bun