开玩笑-测试在每次完成之前执行

时间:2019-03-21 18:42:59

标签: jestjs puppeteer

我有一个测试,其中我的beforeEach方法中有几个前提条件

  • 检查客户端是否存在(如果不存在,请创建一个)
  • 检查门户是否存在(如果不存在,请创建一个)

但是,当我运行测试时,仅满足其中一个条件(创建客户端),而另一个则被忽略。

那是为什么?

import puppeteer from "puppeteer";
const CheckMethods = require('../../../methods/common/checks');
const CreateMethods = require('../../../methods/common/create');
const config = require('../../../../../config/config');

let page;
let browser;
let clientExists;
let portalExists;

describe('Super - User', () => {
  const checks = new CheckMethods();
  const create = new CreateMethods();

  beforeEach(async () => {
    browser = await puppeteer.launch(config.puppeteer);
    page = await browser.newPage();
    await page.setViewport(config.browser);
    await page.goto(`${config.ui_endpoint}/super/#login`, {
      waitUntil: 'networkidle2'
    })
    clientExists = await checks.superClientExists(page)
    console.log('clientExists :', clientExists); // CALLED

    if (!clientExists) {
      await create.createSuperClient(page)
    }
    await page.waitFor(1000)
    portalExists = await checks.superPortalExists(page)
    console.log('portalExists :', portalExists); // NOT CALLED

    if (!portalExists) {
      await create.createSuperPortal(page);
    }

  });

  afterEach(async () => {
    await browser.close();
  });

  it.only('should be able to make client in super a sales rep and assing portal', async () => {
    ..
  }, 150000)
});

1 个答案:

答案 0 :(得分:0)

您是否尝试过向beforeEach调用添加更高的(与标准的相比)超时?像beforeEach(async () => {}, 100000)