【问题标题】:SQL query does not execute in afterAll() function while writing test cases编写测试用例时,在 afterAll() 函数中不执行 SQL 查询
【发布时间】:2019-01-01 18:26:54
【问题描述】:

我正在使用 Protractor Jasmine 编写单元测试用例。

我有一个用 beforeAll() 函数编写的代码,它通过使用 sql 查询从数据库中获取数据来设置数据

同样,有一个 afterAll() 函数,其任务是将数据库中的数据重置为测试用例执行之前的状态

   beforeAll(() => {
     //get database connection

     // setup database data

   });



   it('should .....', () => {
    //code
   });



   afterAll(() => {
     // we can cleanup the database after we're done running our tests
     cleanup.clearAlerts(connection)
       .then(data => {
         //code
       });
   });

这里的 beforeAll() 函数正确执行 sql 查询

然而,afterAll() 函数只是不执行任何清理 sql 查询。

【问题讨论】:

  • 这很难调试。您是否为cleanup.clearAlerts 登录了.catch 引发的错误?您能否提供您的cleanup 代码,并可能在您的代码中显示您调用done 回调的位置。

标签: javascript angularjs unit-testing protractor


【解决方案1】:

afterall 中执行一些浏览器操作来解决问题。

喜欢

afterAll(async function () {
     //your sql query here
    await browser.waitForAngularEnabled(false);
    await browser.get(browser.baseUrl);
});

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 2014-06-16
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多