gpt4 book ai didi

jasmine - Jasmine的toBe匹配器是否支持传第二个参数?

转载 作者:行者123 更新时间:2023-12-02 03:05:18 25 4
gpt4 key购买 nike

我从 Angular 的文档中找到了这个代码片段,但无法从 Jasmine 的文档中找到这个用法。这真的是受支持的功能吗?我只是想确保如果我使用此功能,它不会在升级到较新的次要/补丁版本时意外中断。

expect(masterService.getValue())
.toBe(stubValue, 'service returned stub value');

最佳答案

jasmine.Matchers.toBe 的第二个可选参数(名为 expectationFailOutput)是当 expect 失败时显示的消息。无论是否出现在Jasmine documentation , 它确实受支持并存在于 jasmine.Matchers 接口(interface)的大多数方法中。

interface Matchers {
...
toBe(expected: any, expectationFailOutput?: any): boolean;
toEqual(expected: any, expectationFailOutput?: any): boolean;
toMatch(expected: string | RegExp, expectationFailOutput?: any): boolean;
toBeDefined(expectationFailOutput?: any): boolean;
toBeUndefined(expectationFailOutput?: any): boolean;
toBeNull(expectationFailOutput?: any): boolean;
...
toBeTruthy(expectationFailOutput?: any): boolean;
toBeFalsy(expectationFailOutput?: any): boolean;
...
toContain(expected: any, expectationFailOutput?: any): boolean;
toBeLessThan(expected: number, expectationFailOutput?: any): boolean;
toBeLessThanOrEqual(expected: number, expectationFailOutput?: any): boolean;
toBeGreaterThan(expected: number, expectationFailOutput?: any): boolean;
toBeGreaterThanOrEqual(expected: number, expectationFailOutput?: any): boolean;
toBeCloseTo(expected: number, precision?: any, expectationFailOutput?: any): boolean;

关于jasmine - Jasmine的toBe匹配器是否支持传第二个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59161014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com