gpt4 book ai didi

jestjs - 在 Jest 中有条件地运行测试

转载 作者:行者123 更新时间:2023-12-03 16:29:27 25 4
gpt4 key购买 nike

我一直在比较功能范式和面向对象范式。
作为其中的一部分 - 我想做一些性能测试。
我现在有一些看起来像这样的测试:

it("Some long running performance test", () => {
const result = myFunctionWithLotsOfData();
});
现在,我只是打印此代码运行所需的时间(大约 5000 毫秒)。
我喜欢将 Jest 用于它提供的所有断言和模拟功能,并且它是实时重新加载等。
但是,我不想一直进行这些测试,我会运行创建一个 npm 脚本,例如 npm test:performance ,并且仅当存在环境变量或类似变量时才运行这些测试。
做到这一点的最佳方法是什么?

最佳答案

const itif = (condition) => condition ? it : it.skip;

describe('suite name', () => {
itif(true)('test name', async () => {
// Your test
});
});

关于jestjs - 在 Jest 中有条件地运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58264344/

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