【问题标题】:How to get Asynchronous tests working with Jasmine 1.3.1 and Atom如何使用 Jasmine 1.3.1 和 Atom 进行异步测试
【发布时间】:2019-12-18 05:38:55
【问题描述】:

我正在关注 Asynchronous Support 上的 Jasmine 1.3 文档,但无法让示例正常运行。

我作为spec/async-spec.js 使用的(稍作修改的)源代码如下:

describe("Asynchronous specs", function() {
  var value, flag;

  it("should support async execution of test preparation and expectations", function() {

  runs(function() {
    flag = false;
    value = 0;

    console.log("HERE"); 

    setTimeout(function() {
      console.log("HERE2"); 
      flag = true;
    }, 750);
  });

  waitsFor(function() {
      value++;
      return flag;
  }, "The Value should be incremented", 5000);


  runs(function() {
      expect(value).toBeGreaterThan(0);
    });
  });
});

我正在使用以下命令运行它:

atom --test --timeout 60 spec/async-spec.js

它给出了以下结果:

HERE
F

Asynchronous specs
  it should support async execution of test preparation and expectations
    timeout: timed out after 5000 msec waiting for The Value should be incremented


Finished in 5.746 seconds
1 test, 1 assertion, 1 failure, 0 skipped

我希望测试返回 HEREHERE2 并且断言通过,可惜事实并非如此。

atom --version 的详细信息是:

Atom    : 1.38.2
Electron: 2.0.18
Chrome  : 61.0.3163.100
Node    : 8.9.3

确切的 Jasmine 版本是:1.3.1 revision 1354556913

我对 Atom/Jasmine 测试比较陌生,因此我们将不胜感激。

【问题讨论】:

    标签: javascript unit-testing asynchronous jasmine atom-editor


    【解决方案1】:

    这不是一个理想的解决方案,因为出于一些原因我希望保留默认的 Jasmine 版本,但我发现安装以下软件包使我能够获得更好的异步支持:

    https://www.npmjs.com/package/atom-jasmine2-test-runner

    然后我可以参考 Jasmine 2.9 文档并正确实施它们:

    https://jasmine.github.io/2.9/introduction

    【讨论】:

      猜你喜欢
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-26
      • 1970-01-01
      • 2021-01-18
      相关资源
      最近更新 更多