【问题标题】:Jasmine with promises not showing test results茉莉花承诺不显示测试结果
【发布时间】:2017-11-13 19:13:47
【问题描述】:

所以我有一个非常基本的测试,我想在使用 Jasmine 的测试中检查 Promise 响应的类型。我正在运行一个节点项目并设置了所有这些细节

describe('fail assertion', function() {
        it('should be a failure', function(done) {
            myvideopromise.then(function(resp) {
                expect(true).toBe(false);
                done();
            }).catch(done);
        });
    });

describe('list videos', function() {
        it('should return a list of videos', function(done) {
            myvideopromise.then(function(videos) {
                expect(Array.isArray(videos)).toBe(true);
                done();
            }).catch(done);
        });
    });

但是当我运行它时,我只会在下面看到这个。

Started
F.

Failures:
1) video suite fail assertion should be a failure
  Message:
    Expected true to be false.

“F”是红色的,“.”是红色的。是绿色的。所以看起来它正在正确运行测试断言,但是对于成功它似乎没有显示成功消息。有没有我需要通过的标志之类的?我正在使用它来调用它

jasmine JASMINE_CONFIG_PATH=test/jasmine_config.json

而我的 jasmine_config.json 文件看起来就像

{
    "spec_dir": "test/other/",
    "spec_files": [
        "video_tests.js"
    ]
}

【问题讨论】:

标签: node.js jasmine promise


【解决方案1】:
describe('fail assertion', function () {
        it('should be a failure', function (done) {
            myvideopromise.then(function (resp) {
                expect(true).toBe(true);
                done();
            }).catch(e => {
                done(e);
            });
        });
    });

  describe('list videos', function () {
        it('should return a list of videos', function (done) {
            myvideopromise.then(function (videos) {
                expect(Array.isArray(videos)).toBe(true);
                done();
            }).catch(e => {
                done(e);// it's a failure case
            });
        });
    });

【讨论】:

    猜你喜欢
    • 2023-03-27
    • 2021-05-25
    • 2016-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-24
    相关资源
    最近更新 更多