gpt4 book ai didi

jestjs - 如何将 Jest globalSetup 与 Detox 结合使用

转载 作者:行者123 更新时间:2023-12-01 04:44:20 25 4
gpt4 key购买 nike

我想用globalSetupglobalTeardown来自带有 Detox 的 Jest,以便 detox 设置只发生一次,但如果 init 不是 beforeAll,则 Detox 似乎失败。

有什么建议?

Jest 版本:22.0.4
排毒版本:6.0.4

配置:

"globalSetup": "./setUpDetox.js",
"globalTeardown": "./tearDownDetox.js",

最佳答案

不要使用 globalSetup 和 globalTeardown,而是从 init 中设置和拆除测试环境。只需使用 jest 的 beforeAll 和 afterAll。

e2e/init.js

const detox = require('detox');
const config = require('../package.json').detox;

jest.setTimeout(120000);

beforeAll(async () => {
// custom setup
console.log('Initializing Detox');
await detox.init(config, { launchApp: false });
});

afterAll(async () => {
// custom teardown
await detox.cleanup();
});

e2e/config.json
{
"setupTestFrameworkScriptFile" : "./init.js"
}

关于jestjs - 如何将 Jest globalSetup 与 Detox 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48098712/

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