【问题标题】:Jest-Puppeteer Why warning "Jest did not exit one second after the test run has completedJest-Puppeteer 为什么警告“测试运行完成后一秒钟 Jest 没有退出
【发布时间】:2020-08-26 00:22:51
【问题描述】:

我终于通过了我的第一个笑话木偶测试。 - 下面的代码。 但是我收到了警告。

Jest 在测试运行完成后一秒钟没有退出。 这通常意味着在您的测试中没有停止异步操作。考虑使用 --detectOpenHandles 运行 Jest 来解决此问题。

我在 stackoverflow 上查看了其他问题,看起来我应该使用我添加到测试中的“完成”。但是我仍然收到同样的警告。测试仍然通过。

为什么我会收到警告?

/**
 * @name Onplan Login
 * @desc Logs in and test for correct page title
 */
const puppeteer = require('puppeteer');
const assert = require('assert');
let browser;
beforeAll(async () => {
    browser = await puppeteer.launch({
        headless: false,
        devtools: false,
        slowMo: 50
    });

})

describe('url should be correct"', () => {
    test('url is correct', async done => {
        const page = await browser.newPage();
        await page.goto('https://uat2.onplanapp.com/#/sheet/139');
        await page.waitFor(500);//was 500
        await page.waitFor('#inputEmail');
        await page.type('#inputEmail', 'mayank@onplan.co');
        await page.type('#inputPassword', '123456');
        await page.click('button');//Login
        await page.waitForNavigation();
        await page.waitFor(100);//was 500
        // SELECT COMPANY ON NEXT PAGE
        await page.waitFor('#logn-screenv > form > div.row.logn-screenbody.pb-4.pt-3.px-2 > div:nth-child(2) > div > div > div.css-1hwfws3.custom-scrollbar__value-container > div.css-151xaom-placeholder.custom-scrollbar__placeholder');
        await page.click('#logn-screenv > form > div.row.logn-screenbody.pb-4.pt-3.px-2 > div:nth-child(2) > div > div > div.css-1hwfws3.custom-scrollbar__value-container > div.css-151xaom-placeholder.custom-scrollbar__placeholder');//Login

        // SELECT COMPANY 
        await page.waitFor(500);// was 1000

        // click dropdown to show list of companies
        await page.click('#react-select-2-option-2'); //Test company
        await page.waitFor(300);//was 1000
        await page.click('button[class="btn btn-block mt-3"]');
        //now we go to first page
        const url = await page.url();
        expect(url).toBe('https://uat2.onplanapp.com/#/');
        done();
    }, 20000);

});





【问题讨论】:

    标签: jestjs integration-testing jest-puppeteer


    【解决方案1】:

    在消除警告消息下方添加代码。

    
    afterAll(async done => {
        browser.close()
    
        done();
    });
    

    【讨论】:

      猜你喜欢
      • 2018-12-08
      • 2019-02-05
      • 2023-03-13
      • 1970-01-01
      • 2021-03-28
      • 2019-06-15
      • 2019-09-16
      • 2019-05-24
      • 2021-03-01
      相关资源
      最近更新 更多