【问题标题】:How to use Jest globalSetup with Detox如何将 Jest globalSetup 与 Detox 一起使用
【发布时间】:2018-06-14 09:17:19
【问题描述】:

我想将 Jest 中的 globalSetupglobalTeardown 与 Detox 一起使用,以便 detox 设置只发生一次,但如果 init 不是 beforeAll,则 Detox 似乎会失败。

有什么建议吗?

笑话版本:22.0.4 排毒版:6.0.4

配置:

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

【问题讨论】:

    标签: jestjs detox


    【解决方案1】:

    不要使用 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"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-17
      • 2017-10-31
      • 2018-04-04
      • 2021-06-18
      • 2019-06-08
      • 2021-10-27
      • 1970-01-01
      • 2018-08-09
      相关资源
      最近更新 更多